From ff9efcc84a6b9ea509d65ac955922796b8163565 Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Tue, 11 Oct 2022 01:38:40 -0700 Subject: [PATCH] Add AddService to .NET resource doc (#1843) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add AddService to .NET resource doc * Update content/en/docs/instrumentation/net/resources.md Co-authored-by: Robert Pająk Co-authored-by: Robert Pająk --- content/en/docs/instrumentation/net/resources.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/content/en/docs/instrumentation/net/resources.md b/content/en/docs/instrumentation/net/resources.md index 45242531b4fb..3e8d43222da0 100644 --- a/content/en/docs/instrumentation/net/resources.md +++ b/content/en/docs/instrumentation/net/resources.md @@ -71,9 +71,13 @@ using OpenTelemetry; using OpenTelemetry.Trace; using OpenTelemetry.Resources; +var serviceName = "resource-tutorial-dotnet"; +var serviceVersion = "1.0"; + var resourceBuilder = ResourceBuilder .CreateDefault() + .AddService(serviceName: serviceName, serviceVersion: serviceVersion) .AddAttributes(new Dictionary { ["environment.name"] = "production", @@ -96,12 +100,17 @@ activity?.SetTag("bar", "Hello, World!"); activity?.SetTag("baz", new int[] { 1, 2, 3 }); ``` +In this example, the `service.name` and `service.version` values are +set in code as well. Additionally, `service.instance.id` gets a +default value. + If you run the same command as in [Adding resources with environment -variables](#adding-resources-with-environment-variables), you'll see the -`environment.name` and `team.name` resources in the resource list: +variables](#adding-resources-with-environment-variables), but this time +without `service.name` `service.version`, and `service.instance.id`, +you'll see the `environment.name` and `team.name` resources in the resource list: ```console -env OTEL_RESOURCE_ATTRIBUTES="service.name=resource-tutorial-dotnet,service.namespace=tutorial,service.version=1.0,service.instance.id=`uuidgen`,host.name=`HOSTNAME`,host.type=`uname -m`,os.name=`uname -s`,os.version=`uname -r`" dotnet run +env OTEL_RESOURCE_ATTRIBUTES="service.namespace=tutorial,host.name=`HOSTNAME`,host.type=`uname -m`,os.name=`uname -s`,os.version=`uname -r`" dotnet run Activity.TraceId: d1cbb7787440cc95b325835cb2ff8018 Activity.SpanId: 2ca007300fcb3068