Skip to content

Logs: Integrate in Sentry Client #2920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2f4f785
add log models
denrase May 7, 2025
20506d4
Log in envelope
denrase May 7, 2025
c5f5d6e
add type annotation
denrase May 7, 2025
1a2c038
add cl entry
denrase May 7, 2025
16c4b42
remove unused imports
denrase May 7, 2025
f4ec20b
capture log in client
denrase May 7, 2025
9bf5514
add severity number
denrase May 7, 2025
9cb7821
remove parent SnetryLog, Rename SentryLogItem to SentryLog
denrase May 7, 2025
f50a6ce
Merge branch 'feat/logs-envelope' into feat/logs-client
denrase May 7, 2025
3dee73c
update from model feedback
denrase May 7, 2025
6c74691
add comment to attrib
denrase May 7, 2025
2b9b62e
Merge branch 'feat/logs-envelope' into feat/logs-client
denrase May 7, 2025
ea79978
infer severity number from level
denrase May 7, 2025
39f4130
make default constructor provate for attribute
denrase May 7, 2025
302d22a
Merge branch 'feat/logs-envelope' into feat/logs-client
denrase May 7, 2025
9163b43
add sdk name & version to log attributes
denrase May 7, 2025
58bbb6a
set sentry attributes to log
denrase May 7, 2025
bd95978
Merge branch 'feat/logs' into feat/logs-client
denrase May 7, 2025
5050c90
change client api to take single log
denrase May 7, 2025
a58b17d
update comment with correct dart types
denrase May 7, 2025
874a4ce
add todo for android
denrase May 7, 2025
8ed3a83
set trace id
denrase May 8, 2025
de3a856
disable logs per default
denrase May 8, 2025
3ad3ff0
add BeforeSendLogCallback
denrase May 8, 2025
345d4f6
add cl entry
denrase May 8, 2025
74e69d9
update test text to match api
denrase May 8, 2025
87d52e6
rename var
denrase May 8, 2025
b58cd37
always use propagation context for trace id
denrase May 12, 2025
969dd3c
add comment for empty trace id
denrase May 12, 2025
1a206f4
update comment
denrase May 13, 2025
58535ae
remove experimental, add comments
denrase May 13, 2025
b7f74b3
[Structured Logs]: Buffering and Flushing of Logs (#2930)
denrase May 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
disable logs per default
  • Loading branch information
denrase committed May 8, 2025
commit de3a856fcbf4c023c6c80760190abb4a63a80bad
6 changes: 5 additions & 1 deletion dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ class SentryClient {
SentryLog log, {
Scope? scope,
}) async {
if (!_options.enableLogs) {
return;
}

log.attributes['sentry.sdk.name'] = SentryLogAttribute.string(
_options.sdk.name,
);
Expand Down Expand Up @@ -518,7 +522,7 @@ class SentryClient {
} else if (propagationContext != null) {
log.traceId = propagationContext.traceId;
}

// TODO: Batch in separate PR, so we can send multiple logs at once.
final envelope = SentryEnvelope.fromLogs([log], _options.sdk);

Expand Down
4 changes: 4 additions & 0 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'sentry_exception_factory.dart';
import 'sentry_stack_trace_factory.dart';
import 'transport/noop_transport.dart';
import 'version.dart';
import 'package:meta/meta.dart' as meta;

// TODO: shutdownTimeout, flushTimeoutMillis
// https://api.dart.dev/stable/2.10.2/dart-io/HttpClient/close.html doesn't have a timeout param, we'd need to implement manually
Expand Down Expand Up @@ -531,6 +532,9 @@ class SentryOptions {
/// This is opt-in, as it can lead to existing exception beeing grouped as new ones.
bool groupExceptions = false;

@meta.experimental
bool enableLogs = false;

SentryOptions({String? dsn, Platform? platform, RuntimeChecker? checker}) {
this.dsn = dsn;
if (platform != null) {
Expand Down
16 changes: 16 additions & 0 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,18 @@ void main() {
);
}

test('disabled by default', () async {
final client = fixture.getSut();
final log = givenLog();

await client.captureLog(log);

expect((fixture.transport).logs, isEmpty);
});

test('should capture logs as envelope', () async {
fixture.options.enableLogs = true;

final client = fixture.getSut();
final log = givenLog();
final logJson = log.toJson();
Expand All @@ -1742,6 +1753,7 @@ void main() {
});

test('should add additional info to attributes', () async {
fixture.options.enableLogs = true;
fixture.options.environment = 'test-environment';
fixture.options.release = 'test-release';

Expand Down Expand Up @@ -1800,6 +1812,8 @@ void main() {
});

test('should set trace id if there is a scope span', () async {
fixture.options.enableLogs = true;

final client = fixture.getSut();
final log = givenLog();
final scope = Scope(fixture.options);
Expand All @@ -1817,6 +1831,8 @@ void main() {
test(
'should set trace id from propagation context if there is no scope span',
() async {
fixture.options.enableLogs = true;

final client = fixture.getSut();
final log = givenLog();
final scope = Scope(fixture.options);
Expand Down
Loading