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

Update cartservice docs #485

Merged
merged 7 commits into from
Oct 19, 2022
Merged
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
43 changes: 27 additions & 16 deletions docs/services/cartservice.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ with a Redis caching service for fast access to shopping cart data.

[Cart service source](../../src/cartservice/)

## SDK Initialization
## Traces

### Initialize TracerProvider

The OpenTelemetry .NET SDK should be initialized in your application's
`Startup.cs` as part of the `ConfigureServices` function. When initializing,
optionally specify which instrumentation libraries to leverage. The SDK is
initialized using a builder pattern, where you add each instrumentation library
(with options), and the OTLP Exporter to be used. The SDK will make use of
OpenTelemetry standard environment variables to configure the export endpoints,
resource attributes, and service name.
`TracerProvider` is initialized in the application startup. The required
instrumentation libraries, the exporter to use (OTLP), etc. are enabled as part
of this initialization. Resource attributes and exporter endpoint are
automatically read from OpenTelemetry standard environment variables.

```cs
services.AddOpenTelemetryTracing((builder) => builder
Expand All @@ -26,10 +25,9 @@ resource attributes, and service name.
.AddOtlpExporter());
```

## Traces

OpenTelemetry Tracing in .NET, leverages the existing `Activity` classes as
part of the core runtime.
Note:
OpenTelemetry Tracing in .NET leverages the existing `Activity` class to
represent OpenTelemetry Span.

### Add attributes to auto-instrumented spans

Expand All @@ -40,9 +38,10 @@ Within the execution of auto-instrumented code you can get current span
var activity = Activity.Current;
```

Adding attributes to a span (activity) is accomplished using `SetTag` on the
activity object. In the `AddItem` function from `services/CartService.cs`
several attributes are added to the auto-instrumented span.
Adding attributes (tags in .NET) to a span (activity) is accomplished using
`SetTag` on the activity object. In the `AddItem` function from
`services/CartService.cs` several attributes are added to the auto-instrumented
span.

```cs
activity?.SetTag("app.user.id", request.UserId);
Expand All @@ -62,7 +61,19 @@ added.

## Metrics

TBD
### Initialize MeterProvider

`MeterProvider` is initialized in the application startup. The required
instrumentation libraries, the exporter to use (OTLP), etc. are enabled as part
of this initialization. Resource attributes and exporter endpoint are
automatically read from OpenTelemetry standard environment variables.

```cs
services.AddOpenTelemetryMetrics(builder =>
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
builder.AddRuntimeInstrumentation()
.AddAspNetCoreInstrumentation()
.AddOtlpExporter());;
```

## Logs

Expand Down