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

Fix issue of multiple instances of OpenTelemetry-Sdk EventSource being created #4586

Merged
merged 3 commits into from
Jun 13, 2023

Conversation

utpilla
Copy link
Contributor

@utpilla utpilla commented Jun 12, 2023

Fixes #4516

No other projects other than the SDK project should use OpenTelemetry-Sdk EventSource. Currently, we have multiple projects that link to OpenTelemetrySdkEventSource which is causing users to run into the error: An instance of EventSource with Guid {guid} already exists. Moreover, it doesn't make sense for other components to log messages using SDK's EventSource. These components should use their own dedicated EventSource for that.

Changes

  • Remove compilation of OpenTelemetrySdkEventSource from other projects
  • Update TagTransformer and ConfigurationExtensions to allow components to use their custom EventSource to log warnings

Merge requirement checklist

  • Appropriate CHANGELOG.md files updated for non-trivial changes

@utpilla utpilla requested a review from a team June 12, 2023 20:07
@codecov
Copy link

codecov bot commented Jun 12, 2023

Codecov Report

Merging #4586 (861993a) into main (b3ffb46) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4586      +/-   ##
==========================================
- Coverage   85.14%   85.13%   -0.01%     
==========================================
  Files         320      320              
  Lines       12679    12733      +54     
==========================================
+ Hits        10795    10840      +45     
- Misses       1884     1893       +9     
Impacted Files Coverage Δ
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 79.78% <ø> (-0.43%) ⬇️
.../OpenTelemetry.Exporter.Console/ConsoleExporter.cs 91.66% <100.00%> (+4.16%) ⬆️
...Jaeger/Implementation/JaegerExporterEventSource.cs 70.00% <100.00%> (+20.00%) ⬆️
...rc/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs 87.90% <100.00%> (+0.83%) ⬆️
...tation/OpenTelemetryProtocolExporterEventSource.cs 100.00% <100.00%> (ø)
....Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs 100.00% <100.00%> (ø)
...porter.OpenTelemetryProtocol/OtlpMetricExporter.cs 80.00% <100.00%> (+7.27%) ⬆️
...xporter.OpenTelemetryProtocol/OtlpTraceExporter.cs 91.17% <100.00%> (+2.71%) ⬆️
...Zipkin/Implementation/ZipkinExporterEventSource.cs 70.00% <100.00%> (+20.00%) ⬆️
...rc/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs 89.32% <100.00%> (+0.89%) ⬆️
... and 2 more

... and 4 files with indirect coverage changes

@@ -58,7 +60,7 @@ public bool TryTransformTag(KeyValuePair<string, object> tag, out T result, int?
// If an exception is thrown when calling ToString
// on any element of the array, then the entire array value
// is ignored.
OpenTelemetrySdkEventSource.Log.UnsupportedAttributeType(tag.Value.GetType().ToString(), tag.Key);
LogUnsupportedAttributeType?.Invoke(tag.Value.GetType().ToString(), tag.Key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put "ToString()" under the null check (so we can skip the ToString() call if the callback is null).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wouldn't be calling ToString() if the callback is null as we use the conditional operator ? when calling Invoke: LogUnsupportedAttributeType?.Invoke()

@@ -18,6 +18,8 @@ namespace OpenTelemetry.Internal;

internal abstract class TagTransformer<T>
{
public static Action<string, string> LogUnsupportedAttributeType = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this is becoming bit complicated - e.g. if some code accidentally update this part, it might cause undefined behavior? How do we prevent other OpenTelemetry components from updating this global state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The components that use TagTransformer would have their own instances of its implementation. There is no global state here.

For example, if you were to use ConsoleExporter and OtlpExporter together, each of those exporters would be operating on their instance of TagTransformer as they link this file into their respective dlls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should not use the Sdk project to host these utility files which are only used by other components and not the Sdk itself. We could work on moving such files out of the Sdk project as a follow-up PR.

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ideal, but much better than being buggy.

Copy link
Member

@alanwest alanwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is fine for now, but if we find we run into this general issue we might want to consider a different architecture for shared components.

For example, we have shared components (e.g., TagTransformer, envrironment variable parser, etc) which multiple SDK components consume. Today our architecture is that we effectively compile the shared components into each of the SDK components.

A different architecture might be something like a TagTransformerService which SDK components can get a handle to from the core SDK thereby eliminating the multiple compilations and weird gotchas like we have with EventSource.

But maybe we entertain something like this if we begin to see any recurring friction with the simple approach of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple instances of OpenTelemetry-Sdk EventSource
6 participants