Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Comparing OpenTelemetry Trace API and .NET Activity API #947

Closed
cijothomas opened this issue Jul 29, 2020 · 0 comments
Closed

Comparing OpenTelemetry Trace API and .NET Activity API #947

cijothomas opened this issue Jul 29, 2020 · 0 comments
Labels
documentation Documentation related pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package

Comments

@cijothomas
Copy link
Member

cijothomas commented Jul 29, 2020

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.

OpenTelemetry API Activity API Comments
OpenTelemetry.Trace.TelemetrySpan System.Diagnostics.Activity
span.Name activity.DisplayName
span.SpanContext activity.ActivityContext
span.ParentSpanContext activity.Parent.ActivityContext For in-proc parent
span.ParentSpan activity.Parent For in-proc parent
span.ParentSpanId activity.ParentSpanId For remote parent
span.SpanKind activity.ActivityKind
span.SetAttribute activity.SetTag
span.AddEvent activity.AddEvent
span.Links activity.Links
span.StartTime activity.StartTimeUtc
span.EndTime activity.StartTimeUtc + Activity.Duration
span.IsRecording activity.IsAllDataRequested
@cijothomas cijothomas added the question Further information is requested label Jul 29, 2020
@open-telemetry open-telemetry locked as resolved and limited conversation to collaborators Jul 29, 2020
@reyang reyang added pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package documentation Documentation related labels Jul 30, 2020
@cijothomas cijothomas removed the question Further information is requested label Jul 30, 2020
@cijothomas cijothomas pinned this issue Jul 30, 2020
@reyang reyang unpinned this issue Oct 12, 2020
@cijothomas cijothomas converted this issue into discussion #2941 Feb 24, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
documentation Documentation related pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package
Projects
None yet
Development

No branches or pull requests

2 participants