Skip to content

Commit

Permalink
fix org-dartlang-sdk path on browser
Browse files Browse the repository at this point in the history
  • Loading branch information
lejard-h committed Dec 10, 2018
1 parent 31b276a commit 2344a24
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
22 changes: 19 additions & 3 deletions lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ abstract class SentryClientBase {
/// Used by sentry to differentiate browser from io environment
final String _platform;

final String dartSdkVersion;

SentryClientBase({
this.httpClient,
dynamic clock,
Expand All @@ -84,9 +86,11 @@ abstract class SentryClientBase {
this.environmentAttributes,
String platform,
this.origin,
String dartSdkVersion,
}) : _dsn = Dsn.parse(dsn),
_uuidGenerator = uuidGenerator ?? _generateUuidV4WithoutDashes,
_platform = platform ?? sdkPlatform {
_platform = platform ?? sdkPlatform,
dartSdkVersion = dartSdkVersion ?? 'stable' {
if (clock == null) {
_clock = _getUtcDateTime;
} else {
Expand Down Expand Up @@ -125,7 +129,10 @@ abstract class SentryClientBase {
}

// apply origin to event
event = event.replace(origin: origin);
event = event.replace(
origin: origin,
dartSdkVersion: dartSdkVersion,
);

mergeAttributes(event.toJson(), into: data);
mergeAttributes({'platform': _platform}, into: data);
Expand Down Expand Up @@ -263,13 +270,16 @@ class Event {
this.fingerprint,
this.userContext,
this.origin,
this.dartSdkVersion,
});

/// path origin ot hte excepetion
/// used in browser environment
/// window.location.origin
final String origin;

final String dartSdkVersion;

/// The logger that logged the event.
final String loggerName;

Expand Down Expand Up @@ -365,7 +375,11 @@ class Event {

if (stackTrace != null) {
json['stacktrace'] = <String, dynamic>{
'frames': encodeStackTrace(stackTrace, origin: origin),
'frames': encodeStackTrace(
stackTrace,
origin: origin,
dartSdkVersion: dartSdkVersion,
),
};
}

Expand Down Expand Up @@ -403,6 +417,7 @@ class Event {
List<String> fingerprint,
User userContext,
String origin,
String dartSdkVersion,
}) =>
new Event(
loggerName: loggerName ?? this.loggerName,
Expand All @@ -419,6 +434,7 @@ class Event {
userContext: userContext ?? this.userContext,
level: level ?? this.level,
origin: origin ?? this.origin,
dartSdkVersion: dartSdkVersion ?? this.dartSdkVersion,
);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SentryClientBrowser extends SentryClientBase {
dynamic clock,
UuidGenerator uuidGenerator,
String origin,
String dartSdkVersion,
}) {
httpClient ??= new BrowserClient();
origin ??= '${window.location.origin}/';
Expand All @@ -54,6 +55,7 @@ class SentryClientBrowser extends SentryClientBase {
dsn: dsn,
origin: origin,
platform: browserPlatform,
dartSdkVersion: dartSdkVersion,
);
}

Expand All @@ -65,6 +67,7 @@ class SentryClientBrowser extends SentryClientBase {
String dsn,
String platform,
String origin,
String dartSdkVersion,
}) : super(
httpClient: httpClient,
clock: clock,
Expand All @@ -73,6 +76,7 @@ class SentryClientBrowser extends SentryClientBase {
dsn: dsn,
platform: platform,
origin: origin,
dartSdkVersion: dartSdkVersion,
);

@override
Expand Down
23 changes: 19 additions & 4 deletions lib/src/stack_trace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Map<String, dynamic> asynchronousGapFrameJson = const <String, dynamic>{
List<Map<String, dynamic>> encodeStackTrace(
dynamic stackTrace, {
String origin,
String dartSdkVersion,
}) {
assert(stackTrace is String || stackTrace is StackTrace);
final Chain chain = stackTrace is StackTrace
Expand All @@ -25,18 +26,32 @@ List<Map<String, dynamic>> encodeStackTrace(

final List<Map<String, dynamic>> frames = <Map<String, dynamic>>[];
for (int t = 0; t < chain.traces.length; t += 1) {
frames.addAll(chain.traces[t].frames
.map((f) => encodeStackTraceFrame(f, origin: origin)));
frames.addAll(chain.traces[t].frames.map((f) => encodeStackTraceFrame(
f,
origin: origin,
dartSdkVersion: dartSdkVersion,
)));
if (t < chain.traces.length - 1) frames.add(asynchronousGapFrameJson);
}
return frames.reversed.toList();
}

Map<String, dynamic> encodeStackTraceFrame(Frame frame, {String origin}) {
Map<String, dynamic> encodeStackTraceFrame(
Frame frame, {
String origin,
String dartSdkVersion,
}) {
origin ??= '';

final version = dartSdkVersion ?? 'stable';

final absPath = '$origin${_absolutePathForCrashReport(frame)}'.replaceFirst(
'org-dartlang-sdk://',
'https://raw.githubusercontent.com/dart-lang/sdk/$version',
);

final Map<String, dynamic> json = <String, dynamic>{
'abs_path': '$origin${_absolutePathForCrashReport(frame)}',
'abs_path': absPath,
'function': frame.member,
'lineno': frame.line,
'colno': frame.column,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ dev_dependencies:
args: ">=0.13.0 <2.0.0"
test: ">=0.12.0 <2.0.0"
yaml: ">=2.1.0 <3.0.0"
mockito: ">=2.0.0 <3.0.0"
mockito: "^3.0.0"
3 changes: 2 additions & 1 deletion test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ void testHeaders(
'sentry_secret=secret';
}

if (withUserAgent) expectedHeaders['User-Agent'] = '$sdkName/$sdkVersion';
if (withUserAgent)
expectedHeaders['User-Agent'] = '$sdkName/$sdkVersion';

if (compressPayload) expectedHeaders['Content-Encoding'] = 'gzip';

Expand Down

0 comments on commit 2344a24

Please sign in to comment.