add code samples & sample flag to traces getting started guide (#3099)
This commit is contained in:
parent
eaa2e0ecbd
commit
dbdcf4956e
|
|
@ -50,14 +50,40 @@ What does the above program do?
|
|||
|
||||
The program creates an `ActivitySource` which represents an [OpenTelemetry
|
||||
Tracer](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#tracer).
|
||||
|
||||
```csharp
|
||||
private static readonly ActivitySource MyActivitySource = new ActivitySource(
|
||||
"MyCompany.MyProduct.MyLibrary");
|
||||
```
|
||||
|
||||
The `ActivitySource` instance is used to start an `Activity` which represents an
|
||||
[OpenTelemetry
|
||||
Span](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#span).
|
||||
Span](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#span)
|
||||
and sets several `Tags` on it.
|
||||
|
||||
```csharp
|
||||
using (var activity = MyActivitySource.StartActivity("SayHello"))
|
||||
{
|
||||
activity?.SetTag("foo", 1);
|
||||
activity?.SetTag("bar", "Hello, World!");
|
||||
activity?.SetTag("baz", new int[] { 1, 2, 3 });
|
||||
}
|
||||
```
|
||||
|
||||
An OpenTelemetry
|
||||
[TracerProvider](#tracerprovider)
|
||||
is configured to subscribe to the activities from the source
|
||||
`MyCompany.MyProduct.MyLibrary`, and export it to `ConsoleExporter`.
|
||||
`ConsoleExporter` simply displays it on the console.
|
||||
`ConsoleExporter` simply displays it on the console. The `AlwaysOnSampler` is
|
||||
used by default which does not sample any traces.
|
||||
|
||||
```csharp
|
||||
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddSource("MyCompany.MyProduct.MyLibrary")
|
||||
.AddConsoleExporter()
|
||||
.Build();
|
||||
```
|
||||
|
||||
## TracerProvider
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue