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

Support for OpenTelemetry events in .NET #4778

Open
samsp-msft opened this issue Jul 9, 2024 · 2 comments
Open

Support for OpenTelemetry events in .NET #4778

samsp-msft opened this issue Jul 9, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@samsp-msft
Copy link
Member

samsp-msft commented Jul 9, 2024

Note: I am creating this issue as a placeholder to track conversations and discussion for where & how exactly this feature should land.
This is not a feature for .NET 9

OpenTelemetry Events are a concept that have been in progress for a while, originally primarily driven from the scenario of tracking browser events client, they have been extended to be considered as a replacement for Events in Traces.

The data for events is a specialization of logging, and uses the OTel specification for logs as the basis. An event is essentially a log message with an AnyValue body, and an event.name property.

Approach

We probably want to have a .NET implementation based off of ILogger. It can have an extension method(s) to log events in addition to log messages. It will require a new TState payload to be able to handle the schema for events - primarily that the body is defined as an AnyValue.

ILogger

Events are supposed to be a variation on logging and using the underlying logging infrastructure. It seems like Events should be exposed as:

  • New extension methods on top of ILogger such as
public static void LogEvent(this ILogger logger, string eventName, AnyValue body, params KeyValuePair<string, object>[] attributes)
  • A variation on LoggerMessage.Define to create strongly typed Events
  • A variation on LoggerMessage attribute for annotating methods to create Events

The main challenge with ILogger is the TState object. Events can have their own TState object that can support ToString() and IReadOnlyCollection<KeyValuePair<string, object>> which seem to be the main methods that log implementations use to read the data. An Event needs to support an AnyValue as the body, so that needs to be "flattened". Serializing AnyValue to JSON can solve this problem, and enable compatibility with legacy providers.

AnyValue

OTel/OTLP has the concept of an AnyValue, which is like a traditional OLE variant. It can contain bools, ints, doubles, strings, arrays and maps. The specifications for Attributes in OTel are generally using AnyValue, but we have usually used string or object in our APIs.

We will need to have an implementation of AnyValue that can be used by the OTLP exporter and other parts of OpenTelemetry.NET.

The main concern with AnyValue is how to enable conversion of any random POCO objects in applications that developers are going to want to pass in as state. Creating our own serialization mechanism is problematic and expensive, and we need to consider NativeAOT which limits reflection etc.

The spec for AnyValue has a high overlap with JSON - especially for being able to handle arbitrary combinations of arrays and maps. We should see if we can use the existing JSON serialization as a mechanism for converting arbitrary objects to AnyValue. Having the objects be JSON serializable is also useful for being able to represent the objects when using other exporters or ILogger implementations that are not aware of AnyValue and need to be able to handle the richer data.

@samsp-msft samsp-msft added the enhancement New feature or request label Jul 9, 2024
@samsp-msft samsp-msft self-assigned this Jul 9, 2024
@samsp-msft
Copy link
Member Author

Tagging

  • @noahfalk for general .NET telemetry
  • @reyang, @CodeBlanch for OpenTelemetry.NET
  • @joperezr for Microsoft Extensions - as this could land there as ILogger is defined in extensions
  • @geeknoid as there is considerable overlap with R9, and considerations for redaction etc.

@samsp-msft
Copy link
Member Author

@tommcdon tommcdon added this to the 10.0.0 milestone Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants