Skip to content

Commit 87a4c8f

Browse files
authored
Merge pull request #643 from humivo/DotnetDocs
Update .NET sample app and documentation for metrics
2 parents 76963a9 + 833fb15 commit 87a4c8f

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

src/docs/getting-started/dotnet-sdk.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: 'Getting Started with the .NET SDK on Traces Instrumentation'
2+
title: 'Getting Started with the .NET SDK on Traces and Metrics Instrumentation'
33
description:
44
OpenTelemetry provides different language SDKs to instrument code for collecting telemetry data in the application.
5-
In this doc, we will introduce how to use OpenTelemetry .NET SDK for traces instrumentation in the application
5+
In this doc, we will introduce how to use OpenTelemetry .NET SDK for traces and metrics instrumentation in the application
66
path: '/docs/getting-started/dotnet-sdk'
77
---
88

@@ -16,9 +16,9 @@ In this tutorial, we will introduce how to use OpenTelemetry .NET SDK for manual
1616

1717
## Getting Started
1818

19-
* [Manual Instrumentation on Traces with OpenTelemetry .NET SDK](/docs/getting-started/dotnet-sdk/trace-manual-instr)
19+
* [Manual Instrumentation on Traces and Metrics with OpenTelemetry .NET SDK](/docs/getting-started/dotnet-sdk/manual-instr)
2020

2121

2222
## Sample Code
2323

24-
* [AWS Distro for OpenTelemetry Sample Code with .NET SDK](https://github.com/aws-observability/aws-otel-dotnet/tree/main/integration-test-app)
24+
* [AWS Distro for OpenTelemetry Sample Code with .NET SDK](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/dotnet-sample-app)

src/docs/getting-started/dotnet-sdk/trace-manual-instr.mdx renamed to src/docs/getting-started/dotnet-sdk/manual-instr.mdx

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
---
2-
title: 'Tracing with the AWS Distro for OpenTelemetry .NET SDK and X-Ray'
2+
title: 'Manual Instrumentation for Traces and Metrics with the AWS Distro for OpenTelemetry .NET SDK'
33
description:
44
OpenTelemetry provides different language SDKs to instrument code for collecting telemetry data in the application.
5-
In this tutorial, we will introduce how to use OpenTelemetry .NET SDK for traces instrumentation in the application.
6-
path: '/docs/getting-started/dotnet-sdk/trace-manual-instr'
5+
In this tutorial, we will introduce how to use OpenTelemetry .NET SDK for traces and metrics instrumentation in the application.
6+
path: '/docs/getting-started/dotnet-sdk/manual-instr'
77
---
88

99
import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
1010
import SubSectionSeparator from "components/MdxSubSectionSeparator/subsectionSeparator.jsx"
1111

12-
The AWS Distro for OpenTelemetry .NET SDK contains an extension library for using OpenTelemetry with AWS X-Ray and for instrumenting the AWS SDK. In this tutorial, we will introduce how to manually instrument your application step-by-step using AWS Distro for OpenTelemetry .NET SDK.
12+
The AWS Distro for OpenTelemetry .NET SDK contains an extension library for instrumenting the AWS SDK. In this tutorial, we will introduce how to manually instrument your application for traces and metrics step-by-step using AWS Distro for OpenTelemetry .NET SDK.
1313

1414
<SectionSeparator />
1515

1616
## Requirements
1717

1818
The AWS Distro for OpenTelemetry .NET SDK is compatible for all the officially supported versions of [.NET](https://dotnet.microsoft.com/en-us/download/dotnet) and [.NET Framework](https://dotnet.microsoft.com/en-us/download/dotnet-framework).
1919

20-
**Note**: You’ll also need to have the [AWS Distro for OpenTelemetry Collector](https://aws-otel.github.io/docs/getting-started/collector) running to export traces to X-Ray.
20+
**Note**: You’ll also need to have the [AWS Distro for OpenTelemetry Collector](https://aws-otel.github.io/docs/getting-started/collector) running to export traces and metrics.
2121

2222
<SectionSeparator />
2323

2424
## Installation
2525

26-
In order to instrument your .NET application for tracing, start by downloading the `OpenTelemetry` nuget package to your application.
26+
In order to instrument your .NET application for traces and metrics, start by downloading the `OpenTelemetry` nuget package to your application.
2727

2828
```shell
2929
dotnet add package OpenTelemetry
@@ -40,7 +40,7 @@ If you plan to call another application instrumented with AWS X-Ray SDK, you’l
4040
dotnet add package OpenTelemetry.Contrib.Extensions.AWSXRay
4141
```
4242

43-
In order to export traces from your application to ADOT Collector, you need to install `OpenTelemetry.Exporter.OpenTelemetryProtocol`.
43+
In order to export traces and metics from your application to ADOT Collector, you need to install `OpenTelemetry.Exporter.OpenTelemetryProtocol`.
4444

4545
```shell
4646
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
@@ -50,22 +50,29 @@ By default the OpenTelemetry exporter sends data to an OpenTelemetry collector a
5050

5151
<SectionSeparator />
5252

53-
## Setting up the Global Tracer
53+
## Setting up the Global Tracer and Meter
5454

55-
### Sending Traces to AWS X-Ray
55+
### Sending Traces and Metrics
5656

5757
Configure AWS X-Ray ID generator, propagator and OpenTelemetry Protocol (OTLP) exporter globally in your application as follows. Make sure to call `AddXRayTraceId()` in the very **beginning** when creating `TracerProvider`
58+
Also configure the meter provider and add a meter of your choice as well as the OpenTelemetry Protocol (OTLP) exporter.
5859

5960
```csharp
6061
using OpenTelemetry;
6162
using OpenTelemetry.Contrib.Extensions.AWSXRay.Trace;
6263
using OpenTelemetry.Trace;
6364

6465
var tracerProvider = Sdk.CreateTracerProviderBuilder()
66+
.AddSource("ActivitySourceName")
6567
.AddXRayTraceId() // for generating AWS X-Ray compliant trace IDs
6668
.AddOtlpExporter() // default address localhost:4317
6769
.Build();
6870

71+
var meterProvider = Sdk.CreateMeterProviderBuilder()
72+
.AddMeter("example_meter")
73+
.AddOtlpExporter()
74+
.Build();
75+
6976
Sdk.SetDefaultTextMapPropagator(new AWSXRayPropagator()); // configure AWS X-Ray propagator
7077
```
7178

@@ -152,8 +159,30 @@ Attributes are converted to metadata by default. If you configure your collector
152159

153160
For more information about the activity API, see the [OpenTelemetry .NET SDK's developer guide](https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Api#instrumenting-a-libraryapplication-with-net-activity-api).
154161

162+
### Creating Metrics
163+
164+
Similarly to Traces, you can create custom metrics in your application using the OpenTelemetry API and SDK.
165+
166+
In the following example application we demonstrate how to use metric instruments to record metrics with a Counter.
167+
168+
```csharp
169+
using System.Threading.Tasks;
170+
171+
Meter meter = new Meter("example_meter", "1.0");
172+
173+
totalTimeSentObserver = meter.CreateCounter<int>("time_alive",
174+
"ms",
175+
"Measures the total time the application has been alive");
176+
177+
while (true) {
178+
var delayTask = Task.Delay(1000);
179+
await Task.Run(() => totalTimeSentObserver.Add(1, new KeyValuePair<string, object>("attribute", "sample")));
180+
await delayTask;
181+
}
182+
```
183+
155184
<SectionSeparator />
156185

157186
## Sample Application
158187

159-
Take a reference to the [sample application](https://github.com/aws-observability/aws-otel-dotnet/tree/main/integration-test-app) that is instrumented by ADOT and OpenTelemetry .NET SDK.
188+
Take a reference to the [sample application](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/dotnet-sample-app) that is instrumented by ADOT and OpenTelemetry .NET SDK.

0 commit comments

Comments
 (0)