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

[PLAT-12988] Set bugsnag.span.category to 'custom' for custom spans #336

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog

### Bug fixes

* Set bugsnag.span.category to 'custom' for custom spans.
[336](https://github.com/bugsnag/bugsnag-cocoa-performance/pull/336)

* Fix visionOS compilation errors. Note that visionOS is not yet officially supported.
[327](https://github.com/bugsnag/bugsnag-cocoa-performance/pull/327)

Expand Down
4 changes: 2 additions & 2 deletions Sources/BugsnagPerformance/Private/BugsnagPerformanceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class BugsnagPerformanceImpl: public PhasedStartup {

void reportNetworkSpan(NSURLSessionTask *task, NSURLSessionTaskMetrics *metrics) noexcept;

BugsnagPerformanceSpan *startSpan(NSString *name) noexcept;
BugsnagPerformanceSpan *startCustomSpan(NSString *name) noexcept;

BugsnagPerformanceSpan *startSpan(NSString *name, BugsnagPerformanceSpanOptions *options) noexcept;
BugsnagPerformanceSpan *startCustomSpan(NSString *name, BugsnagPerformanceSpanOptions *options) noexcept;

BugsnagPerformanceSpan *startViewLoadSpan(NSString *name, BugsnagPerformanceViewType viewType) noexcept;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,17 @@

#pragma mark Spans

BugsnagPerformanceSpan *BugsnagPerformanceImpl::startSpan(NSString *name) noexcept {
BugsnagPerformanceSpan *BugsnagPerformanceImpl::startCustomSpan(NSString *name) noexcept {
SpanOptions options;
auto span = tracer_->startCustomSpan(name, options);
[span internalSetMultipleAttributes:spanAttributesProvider_->customSpanAttributes()];
return span;
}

BugsnagPerformanceSpan *BugsnagPerformanceImpl::startSpan(NSString *name, BugsnagPerformanceSpanOptions *optionsIn) noexcept {
BugsnagPerformanceSpan *BugsnagPerformanceImpl::startCustomSpan(NSString *name, BugsnagPerformanceSpanOptions *optionsIn) noexcept {
auto options = SpanOptions(optionsIn);
auto span = tracer_->startCustomSpan(name, options);
[span internalSetMultipleAttributes:spanAttributesProvider_->customSpanAttributes()];
return span;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SpanAttributesProvider {
NSMutableDictionary *viewLoadSpanAttributes(NSString *className, BugsnagPerformanceViewType viewType) noexcept;
NSMutableDictionary *preloadedViewLoadSpanAttributes(NSString *className, BugsnagPerformanceViewType viewType) noexcept;
NSMutableDictionary *viewLoadPhaseSpanAttributes(NSString *className, NSString *phase) noexcept;
NSMutableDictionary *customSpanAttributes() noexcept;

static NSString *httpUrlAttributeKey();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,10 @@ static void addNonZero(NSMutableDictionary *dict, NSString *key, NSNumber *value
@"bugsnag.phase": phase,
}.mutableCopy;
}

NSMutableDictionary *
SpanAttributesProvider::customSpanAttributes() noexcept {
return @{
@"bugsnag.span.category": @"custom",
}.mutableCopy;
}
4 changes: 2 additions & 2 deletions Sources/BugsnagPerformance/Public/BugsnagPerformance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ + (void)startWithConfiguration:(BugsnagPerformanceConfiguration *)configuration
}

+ (BugsnagPerformanceSpan *)startSpanWithName:(NSString *)name {
return BugsnagPerformanceLibrary::getBugsnagPerformanceImpl()->startSpan(name);
return BugsnagPerformanceLibrary::getBugsnagPerformanceImpl()->startCustomSpan(name);
}

+ (BugsnagPerformanceSpan *)startSpanWithName:(NSString *)name options:(BugsnagPerformanceSpanOptions *)options {
return BugsnagPerformanceLibrary::getBugsnagPerformanceImpl()->startSpan(name, options);
return BugsnagPerformanceLibrary::getBugsnagPerformanceImpl()->startCustomSpan(name, options);
}

+ (BugsnagPerformanceSpan *)startViewLoadSpanWithName:(NSString *)name viewType:(BugsnagPerformanceViewType)viewType {
Expand Down
3 changes: 3 additions & 0 deletions features/default/manual_spans.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Feature: Manual creation of spans
* a span field "name" equals "WillRetry"
* a span field "name" equals "Success"
* every span bool attribute "bugsnag.span.first_class" is true
* every span string attribute "bugsnag.span.category" equals "custom"

Scenario: Manually start and end a span
Given I run "ManualSpanScenario"
Expand Down Expand Up @@ -47,6 +48,7 @@ Feature: Manual creation of spans
* the trace payload field "resourceSpans.0.resource" string attribute "service.version" equals "10.0"
* the trace payload field "resourceSpans.0.resource" string attribute "telemetry.sdk.name" equals "bugsnag.performance.cocoa"
* the trace payload field "resourceSpans.0.resource" string attribute "telemetry.sdk.version" matches the regex "[0-9]+\.[0-9]+\.[0-9]+"
* every span string attribute "bugsnag.span.category" equals "custom"

Scenario: Starting and ending a span before starting the SDK
Given I run "ManualSpanBeforeStartScenario"
Expand All @@ -66,6 +68,7 @@ Feature: Manual creation of spans
* the trace payload field "resourceSpans.0.resource" string attribute "telemetry.sdk.version" matches the regex "[0-9]+\.[0-9]+\.[0-9]+"
* the trace payload field "resourceSpans.0.resource" string attribute "bugsnag.app.bundle_version" equals "42.42"
* the trace payload field "resourceSpans.0.resource" string attribute "service.version" equals "42"
* every span string attribute "bugsnag.span.category" equals "custom"

Scenario: Manually report a view load span
Given I run "ManualViewLoadScenario"
Expand Down
Loading