Skip to content

Support for enriching activities#4284

Closed
Haydabase wants to merge 9 commits into
npgsql:mainfrom
Haydabase:otel-enrich
Closed

Support for enriching activities#4284
Haydabase wants to merge 9 commits into
npgsql:mainfrom
Haydabase:otel-enrich

Conversation

@Haydabase

@Haydabase Haydabase commented Jan 19, 2022

Copy link
Copy Markdown

This PR addresses #4192, using a similar Enrich signature to the Http tracing instrumentation (here).

Documentation PR: npgsql/doc#177

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this looks great! See mostly minor comments below.

One thing I'm slightly concerned about, is that Npgsql will probably support other activities, and not just command execution (e.g. physical connection open, COPY, prepare...). Because of this, having Enrich correspond to command execution could be problematic, so maybe something like EnrichCommandExecution?

Comment thread test/Npgsql.OpenTelemetry.Tests/Npgsql.OpenTelemetry.Tests.csproj Outdated
Comment thread test/Npgsql.OpenTelemetry.Tests/NpgsqlTracingOptionsTests.cs
Comment thread src/Npgsql.OpenTelemetry/README.md Outdated
Comment thread src/Npgsql.OpenTelemetry/README.md Outdated
Comment thread src/Npgsql.OpenTelemetry/README.md Outdated
Comment thread Npgsql.sln Outdated
Comment thread src/Npgsql.OpenTelemetry/Npgsql.OpenTelemetry.csproj
Comment thread src/Npgsql.OpenTelemetry/NpgsqlTracingInstrumentation.cs Outdated
configure?.Invoke(options);
return builder
.AddSource("Npgsql")
.AddInstrumentation(() => new NpgsqlTracingInstrumentation(options));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know the OpenTelemetry very well - what's the advantage of AddInstrumentation with NpgsqlTracingInstrumentation here over simply injecting NpgsqlActivitySource.Options directly in this method?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think we only want to set NpgsqlActivitySource.Options if and when Build() is called on the TraceProviderBuilder. I also think technically we want to remove those options once the built TracerProvider has been disposed. Using an instrumentation factory that returns an IDisposable gives us that behaviour.
(See 3.i here)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't that documentation section only relevant when the instrumentation library is separate/external, because the main library isn't instrumented? In other words, I think what we're doing qualifies as part of "make every library observable out of the box by having them call OpenTelemetry API directly" (the first sentence).

On a related note, I don't think this config stuff qualifies as "state management", which is what I think the AddInstrumentation API is about.

But I'm far from an expert on all this - let me know how you see things.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think regardless of if the documentation section is intended to be for just separate instrumentations, the behaviour it gives us is desirable here: only set NpgsqlActivitySource.Options if and when Build() is called on the TraceProviderBuilder, and unset it when the TraceProvider is disposed.

Comment thread src/Npgsql/NpgsqlActivitySource.cs Outdated
- nullability of options
- documentation
@Haydabase

Copy link
Copy Markdown
Author

Hey thanks so much for taking the time to review.

One thing I'm slightly concerned about, is that Npgsql will probably support other activities, and not just command execution (e.g. physical connection open, COPY, prepare...). Because of this, having Enrich correspond to command execution could be problematic, so maybe something like EnrichCommandExecution?

I've updated as suggested - it might be worth also adding filtering when there are multiple types of spans generated, as I suspect some users might only be interested in a subset, especially if they are paying per span ingested.

@Haydabase Haydabase requested a review from roji January 20, 2022 19:11
@tl-david-hayden

Copy link
Copy Markdown

@roji You mentioned this being for v7.0 - what is the release schedule for that?

@roji

roji commented Jan 21, 2022

Copy link
Copy Markdown
Member

I've updated as suggested - it might be worth also adding filtering when there are multiple types of spans generated, as I suspect some users might only be interested in a subset, especially if they are paying per span ingested.

Absolutely - we'll need to think about that when we add those extra activities.

You mentioned this being for v7.0 - what is the release schedule for that?

We're aligned with the .NET release schedule, so 7.0 should go out in November - a bit far away, I know. In theory we could do a 6.1 release, but that complicates things and I'd rather avoid it unless there are some very good reasons.

Note also that I have various other plans for OpenTelemetry and diagnostics in general - so it's good to have some time on this.

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @Haydabase, looks almost ready; just details around the tuple parameter etc.

@roji

roji commented Feb 16, 2022

Copy link
Copy Markdown
Member

@Haydabase pinging to make sure this doesn't get forgotten :) It's really almost ready :)

@Haydabase

Copy link
Copy Markdown
Author

@roji Sorry for the ping back on this, I know it took me a little while to respond to the previous comment, but I think this should be good to go now. I have another PR lined up that build on this here: #4430

@roji

roji commented Jun 5, 2022

Copy link
Copy Markdown
Member

@Haydabase sorry, unfortunately I'm currently busy with other things... I'll definitely be back to concentrating on OpenTelemetry before 7.0, but it will likely happen later in the release cycle...

# Conflicts:
#	Directory.Packages.props
@Haydabase

Copy link
Copy Markdown
Author

@roji Sorry for another ping, just thinking it is likely less than a month to the v7 release - is this likely to get in?

@NinoFloris

Copy link
Copy Markdown
Member

This PR was superseded by #5853 which was released in Npgsql 9.0. Thanks for the attempt @Haydabase, don't hesitate to open issues if you run into limitations of the current functionality.

@NinoFloris NinoFloris closed this Oct 29, 2025
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.

4 participants