Sitelet https://github.com/npgsql/npgsql/pull/6051
Skip to content

Add basic testing for tracing - #6051

Merged
vonzshik merged 7 commits into
mainfrom
4285-tracing-basic-testing
Mar 20, 2025
Merged

vonzshik merged 7 commits into
mainfrom
4285-tracing-basic-testing

Conversation

@vonzshik

Copy link
Copy Markdown
Contributor

Closes #4285

@vonzshik
vonzshik marked this pull request as ready for review March 17, 2025 12:12
@vonzshik
vonzshik requested a review from roji as a code owner March 17, 2025 12:12

@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! If you're really in the mood for observability testing, I remember there's also a package specifically for helping test metrics too.

Comment thread src/Npgsql/NpgsqlActivitySource.cs Outdated
{
{ "exception.type", ex.GetType().FullName },
{ "exception.message", ex.Message },
// TODO: only set ex.StackTrace?

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.

Hmm, good point... We should check what others (e.g. ASP.NET) are doing here...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is a new method Activity.AddException added with .NET 9 which calls Exception.ToString, so we're probably fine...

https://github.com/dotnet/runtime/blob/main/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs#L595

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm actually more interested whether we should set Activity.Status...

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.

🤷

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.

There is a new method Activity.AddException added with .NET 9

Would be nice to use that even if it doesn't do much else (maybe it will at some point?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would be nice to use that even if it doesn't do much else (maybe it will at some point?)

Well, whenever we actually upgrade from .NET 8...

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.

We can multi-target to .NET 9 at any time for Npgsql 10, though if it's just for that may indeed not be worth it... Can at least add a comment though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Also we now set Activity.Status just in case (remote consumers should already be able to via otel.status_code tag).

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.

Do we need both Activity.Status and otel.status_code? Maybe we can remove the latter?

internal static void CommandStop(Activity activity)
{
activity.SetTag("otel.status_code", "OK");
activity.SetStatus(ActivityStatusCode.Ok);

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.

Is this a dup of the line just above? Or are there two different things? Same below for exception.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not exactly. Activity.Status (and Activity.Description) do not add any tags, they're essentially just fields in Activity and it's up to exporters to populate tags depending on Activity.Status. So in case there's an exporter which doesn't react on Activity.Status, then these tags will never be added if we remove them from there.
I'm more-or-less OK with removing explicit tags.

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 enough about this... What do ASP.NET do, for instance?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 for looking - I guess we can do the same then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sure

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.

OpenTelemetry: add test coverage

2 participants