Skip to content

Commit

Permalink
Send service.name in resource attributes (#80)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert <[email protected]>
  • Loading branch information
robert-smartbear and Robert authored Sep 4, 2024
1 parent b624795 commit 5a82a98
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:bugsnag_flutter_performance/bugsnag_flutter_performance.dart';
import 'scenario.dart';

class CustomServiceNameScenario extends Scenario {
@override
Future<void> run() async {
await startBugsnag(serviceName: "com.custom.serviceName");
setMaxBatchSize(1);
doSimpleSpan('CustomServiceNameScenario');
}
}
2 changes: 2 additions & 0 deletions features/fixture_resources/lib/scenarios/scenario.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ abstract class Scenario {
String? releaseStage,
List<String>? enabledReleaseStages,
List<RegExp>? tracePropagationUrls,
String? serviceName,
String? appVersion,
bool shouldUseNotifier = false,
double? samplingProbability,
Expand All @@ -57,6 +58,7 @@ abstract class Scenario {
releaseStage: releaseStage,
enabledReleaseStages: enabledReleaseStages,
tracePropagationUrls: tracePropagationUrls,
serviceName: serviceName,
appVersion: appVersion,
samplingProbability: samplingProbability,
);
Expand Down
2 changes: 2 additions & 0 deletions features/fixture_resources/lib/scenarios/scenarios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:mazerunner/scenarios/auto_instrument_view_load_basic_scenario.da
import 'package:mazerunner/scenarios/auto_instrument_view_load_nested_scenario.dart';
import 'package:mazerunner/scenarios/correlation_null_scenario.dart';
import 'package:mazerunner/scenarios/correlation_simple_scenario.dart';
import 'package:mazerunner/scenarios/custom_service_name_scenario.dart';
import 'package:mazerunner/scenarios/dart_io_traceparent_scenario.dart';
import 'package:mazerunner/scenarios/fixed_sampling_probability_one_scenario.dart';
import 'package:mazerunner/scenarios/fixed_sampling_probability_zero_scenario.dart';
Expand Down Expand Up @@ -125,4 +126,5 @@ final List<ScenarioInfo<Scenario>> scenarios = [
() => FixedSamplingProbabilityOneScenario()),
ScenarioInfo('FixedSamplingProbabilityZeroScenario',
() => FixedSamplingProbabilityZeroScenario()),
ScenarioInfo('CustomServiceNameScenario', () => CustomServiceNameScenario()),
];
10 changes: 10 additions & 0 deletions features/resource_attributes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ Feature: Resource Attributes
* every span field "name" equals "CustomEnabledReleaseStageScenario"
* the trace payload field "resourceSpans.0.resource" string attribute "deployment.environment" equals "CustomEnabledReleaseStageScenario"

Scenario: Custom service name
When I run "CustomServiceNameScenario"
And I wait for 1 span
Then the trace "Content-Type" header equals "application/json"
* the trace "Bugsnag-Sent-At" header matches the regex "^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\dZ$"
* the trace "Bugsnag-Span-Sampling" header equals "1:1"
* every span field "name" equals "CustomServiceNameScenario"
* the trace payload field "resourceSpans.0.resource" string attribute "service.name" equals "com.custom.serviceName"

Scenario: Custom app version
When I run "CustomAppVersionScenario"
And I wait for 1 span
Expand Down Expand Up @@ -46,6 +55,7 @@ Feature: Resource Attributes
* the trace payload field "resourceSpans.0.resource" string attribute "telemetry.sdk.name" equals "bugsnag.performance.flutter"
* the trace payload field "resourceSpans.0.resource" string attribute "telemetry.sdk.version" exists
* the trace payload field "resourceSpans.0.resource" string attribute "device.model.identifier" exists
* the trace payload field "resourceSpans.0.resource" string attribute "service.name" equals "com.bugsnag.mazerunner"
* the trace payload field "resourceSpans.0.resource" string attribute "service.version" equals "1.0.0"
* the trace payload field "resourceSpans.0.resource" string attribute "device.manufacturer" exists
* the trace payload field "resourceSpans.0.resource" string attribute "host.arch" exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class BugsnagPerformance {
String? releaseStage,
List<String>? enabledReleaseStages,
List<RegExp>? tracePropagationUrls,
String? serviceName,
String? appVersion,
double? samplingProbability,
}) {
Expand All @@ -52,6 +53,7 @@ class BugsnagPerformance {
releaseStage: releaseStage,
enabledReleaseStages: enabledReleaseStages,
tracePropagationUrls: tracePropagationUrls,
serviceName: serviceName,
appVersion: appVersion,
samplingProbability: samplingProbability,
);
Expand Down
3 changes: 3 additions & 0 deletions packages/bugsnag_flutter_performance/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ abstract class BugsnagPerformanceClient {
networkRequestCallback,
String? releaseStage,
List<String>? enabledReleaseStages,
String? serviceName,
String? appVersion,
});

Expand Down Expand Up @@ -131,6 +132,7 @@ class BugsnagPerformanceClientImpl implements BugsnagPerformanceClient {
String? releaseStage,
List<String>? enabledReleaseStages,
List<RegExp>? tracePropagationUrls,
String? serviceName,
String? appVersion,
double? samplingProbability,
}) async {
Expand All @@ -147,6 +149,7 @@ class BugsnagPerformanceClientImpl implements BugsnagPerformanceClient {
releaseStage: releaseStage ?? getDeploymentEnvironment(),
enabledReleaseStages: enabledReleaseStages,
tracePropagationUrls: tracePropagationUrls,
serviceName: serviceName,
appVersion: appVersion,
samplingProbability: samplingProbability,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BugsnagPerformanceConfiguration {
this.releaseStage,
this.enabledReleaseStages,
this.tracePropagationUrls,
this.serviceName,
this.appVersion,
this.samplingProbability,
});
Expand All @@ -20,6 +21,7 @@ class BugsnagPerformanceConfiguration {
List<RegExp>? tracePropagationUrls;
String? releaseStage;
List<String>? enabledReleaseStages;
String? serviceName;
String? appVersion;
double? samplingProbability;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class ResourceAttributesProviderImpl implements ResourceAttributesProvider {
"stringValue": await getDeviceModel(deviceInfo),
}
},
{
"key": "service.name",
"value": {
"stringValue": config?.serviceName ?? packageInfo.packageName,
}
},
{
"key": "service.version",
"value": {
Expand Down

0 comments on commit 5a82a98

Please sign in to comment.