Skip to content
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

fix: event SDK info should depend on the configured options #1853

Merged
merged 2 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Implement description for SentryBreadcrumb (#1880)

### Fixes

- Propagate configured SDK info from options to events (#1853)

## 7.16.1

### Fixes
Expand Down
46 changes: 25 additions & 21 deletions Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "SentryOutOfMemoryTracker.h"
#import "SentrySDK+Private.h"
#import "SentryScope+Private.h"
#import "SentrySdkInfo.h"
#import "SentryStacktraceBuilder.h"
#import "SentryThreadInspector.h"
#import "SentryTraceState.h"
Expand Down Expand Up @@ -363,7 +364,11 @@ - (void)captureSession:(SentrySession *)session
return;
}

SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithSession:session];
SentryEnvelopeItem *item = [[SentryEnvelopeItem alloc] initWithSession:session];
SentryEnvelopeHeader *envelopeHeader =
[[SentryEnvelopeHeader alloc] initWithId:nil sdkInfo:self.options.sdkInfo traceState:nil];
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader
singleItem:item];
[self captureEnvelope:envelope];
}

Expand Down Expand Up @@ -568,30 +573,29 @@ - (SentryEvent *_Nullable)callEventProcessors:(SentryEvent *)event

- (void)setSdk:(SentryEvent *)event
{
// Every integration starts with "Sentry" and ends with "Integration". To keep the payload of
// the event small we remove both.
NSMutableArray<NSString *> *integrations = [NSMutableArray new];
for (NSString *integration in self.options.enabledIntegrations) {
NSString *withoutSentry = [integration stringByReplacingOccurrencesOfString:@"Sentry"
withString:@""];
NSString *trimmed = [withoutSentry stringByReplacingOccurrencesOfString:@"Integration"
withString:@""];
[integrations addObject:trimmed];
}

NSMutableDictionary *sdk = @{
@"name" : SentryMeta.sdkName,
@"version" : SentryMeta.versionString,
@"integrations" : integrations
if (event.sdk) {
return;
}
.mutableCopy;

if (nil == event.sdk) {
if (event.extra[@"__sentry_sdk_integrations"]) {
[sdk setValue:event.extra[@"__sentry_sdk_integrations"] forKey:@"integrations"];
id integrations = event.extra[@"__sentry_sdk_integrations"];
if (!integrations) {
integrations = [NSMutableArray new];
for (NSString *integration in self.options.enabledIntegrations) {
// Every integration starts with "Sentry" and ends with "Integration". To keep the
// payload of the event small we remove both.
NSString *withoutSentry = [integration stringByReplacingOccurrencesOfString:@"Sentry"
withString:@""];
NSString *trimmed = [withoutSentry stringByReplacingOccurrencesOfString:@"Integration"
withString:@""];
[integrations addObject:trimmed];
}
event.sdk = sdk;
}

event.sdk = @{
@"name" : self.options.sdkInfo.name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value from SentryMeta is added to envelope headers so Relay can also know what SDK is sending the data to its backend. This can help us troubleshoot issues where one SDK is sending bad data.

Ideally we find a way to change that value and affect all corners of the SDK, instead of reporting a different value here and on the envelope header, for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we find a way to change that value and affect all corners of the SDK, instead of reporting a different value here and on the envelope header, for example.

I completely agree and I've had another look and updated all code paths from the actual SDK code (at least I think I've done all of them). The remaining call paths are either from test code or public APIs that I can't touch without breaking changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to add/update tests to verify the configured SDK override is actually propagated to events and envelopes, but I really don't know which test would be a good candidate to update. Maybe someone from the maintainers could have a look and make the change, or at least point me to the appropriate test case.

@"version" : self.options.sdkInfo.version,
@"integrations" : integrations
};
}

- (void)setUserInfo:(NSDictionary *)userInfo withEvent:(SentryEvent *)event
Expand Down
21 changes: 16 additions & 5 deletions Sources/Sentry/SentryTransportAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "SentryEnvelope.h"
#import "SentryEvent.h"
#import "SentryOptions.h"
#import "SentryUserFeedback.h"
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -57,8 +58,10 @@ - (void)sendEvent:(SentryEvent *)event
attachments:attachments];
[items addObjectsFromArray:additionalEnvelopeItems];

SentryEnvelopeHeader *envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:event.eventId
traceState:traceState];
SentryEnvelopeHeader *envelopeHeader =
[[SentryEnvelopeHeader alloc] initWithId:event.eventId
sdkInfo:self.options.sdkInfo
traceState:traceState];
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader items:items];

[self sendEnvelope:envelope];
Expand All @@ -73,8 +76,10 @@ - (void)sendEvent:(SentryEvent *)event
attachments:attachments];
[items addObject:[[SentryEnvelopeItem alloc] initWithSession:session]];

SentryEnvelopeHeader *envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:event.eventId
traceState:traceState];
SentryEnvelopeHeader *envelopeHeader =
[[SentryEnvelopeHeader alloc] initWithId:event.eventId
sdkInfo:self.options.sdkInfo
traceState:traceState];

SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader items:items];

Expand All @@ -83,7 +88,13 @@ - (void)sendEvent:(SentryEvent *)event

- (void)sendUserFeedback:(SentryUserFeedback *)userFeedback
{
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithUserFeedback:userFeedback];
SentryEnvelopeItem *item = [[SentryEnvelopeItem alloc] initWithUserFeedback:userFeedback];
SentryEnvelopeHeader *envelopeHeader =
[[SentryEnvelopeHeader alloc] initWithId:userFeedback.eventId
sdkInfo:self.options.sdkInfo
traceState:nil];
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader
singleItem:item];
[self sendEnvelope:envelope];
}

Expand Down