You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Comparing the OpenTelemetry Trace API and .NET Activity API
Introduction
Starting with 5.0.0 version of DiagnosticSource, the recommendation from OpenTelemetry .NET is to use .NET Activity API as the OpenTelemetry Tracing API. .NET's Activity API existed for a long time, and has been recently improved (in 5.0.0) to enable all OpenTelemetry scenarios. The OpenTelemetry .NET API ships a shim on top of the Activity class, which may be used, as it offers familiar terminology like Span and Tracer. Irrespective of the API used, the final outcome is still the same - Processors and Exporters always get Activity objects. In short, Activity in .NET represents the OpenTelemetry Span.
.NET Activity API ships as part of the nuget System.Diagnostics.DiagnosticSource. Version 5.0.0 of the package is required, which was released along with .NET 5 release, but the package supports every versions of .NET which are officially supported. This includes .NET Framework 4.5.2 and above. .NET Core 2.XX, .NET Core 3.XX and, .NET 5.
Comparing the APIs
TracerProvider
As the name indicates, TracerProvider provides Tracer. The .NET equivalent of Tracer is ActivitySource. .NET has no equivalent concept of TracerProvider. ActivitySources are not obtained from a TracerProvider, but are directly instantiated with name (and version optionally).
OpenTelemetry API
Activity API
var tracer = TracerProvider.Default.GetTracer("name", "version")
var activitySource = new ActivitySource("name", "version")
Tracer
Tracer is responsible for creating Span. It also has a method to get the current active Span. In .NET, ActivitySource is the equivalent of the Tracer. Differences are noted below.
OpenTelemetry API
Activity API
Comments
tracer.StartActiveSpan()
activitySource.StartActivity()
Tracer.Current
Activity.Current
Note that the .Current is obtained from Activity, not ActivitySource.
tracer.StartSpan
No equivalent. Starting an activity always makes it as the current.
Span
A Span represents a single operation within a trace. In .NET Activity class represents the span.
This discussion was converted from issue #947 on February 24, 2022 19:17.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Comparing the OpenTelemetry Trace API and .NET Activity API
Introduction
Starting with 5.0.0 version of DiagnosticSource, the recommendation from OpenTelemetry .NET is to use .NET Activity API as the OpenTelemetry Tracing API. .NET's Activity API existed for a long time, and has been recently improved (in 5.0.0) to enable all OpenTelemetry scenarios. The OpenTelemetry .NET API ships a shim on top of the Activity class, which may be used, as it offers familiar terminology like
Span
andTracer
. Irrespective of the API used, the final outcome is still the same - Processors and Exporters always getActivity
objects. In short,Activity
in .NET represents the OpenTelemetry Span..NET Activity API ships as part of the nuget System.Diagnostics.DiagnosticSource. Version 5.0.0 of the package is required, which was released along with .NET 5 release, but the package supports every versions of .NET which are officially supported. This includes .NET Framework 4.5.2 and above. .NET Core 2.XX, .NET Core 3.XX and, .NET 5.
Comparing the APIs
TracerProvider
As the name indicates, TracerProvider provides Tracer. The .NET equivalent of
Tracer
isActivitySource
. .NET has no equivalent concept ofTracerProvider
.ActivitySource
s are not obtained from aTracerProvider
, but are directly instantiated with name (and version optionally).Tracer
Tracer is responsible for creating Span. It also has a method to get the current active Span. In .NET,
ActivitySource
is the equivalent of the Tracer. Differences are noted below.Span
A Span represents a single operation within a trace. In .NET
Activity
class represents the span.Beta Was this translation helpful? Give feedback.
All reactions