Skip to content

Commit

Permalink
Add AddService to .NET resource doc (#1843)
Browse files Browse the repository at this point in the history
* Add AddService to .NET resource doc

* Update content/en/docs/instrumentation/net/resources.md

Co-authored-by: Robert Pająk <[email protected]>

Co-authored-by: Robert Pająk <[email protected]>
  • Loading branch information
cartermp and pellared authored Oct 11, 2022
1 parent 68a8ea7 commit ff9efcc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions content/en/docs/instrumentation/net/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>
{
["environment.name"] = "production",
Expand All @@ -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
Expand Down

0 comments on commit ff9efcc

Please sign in to comment.