Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@manandre
Copy link
Collaborator

Closes #5838

@kerams
Copy link

kerams commented Mar 14, 2025

Could this go out in a minor version release or will OTel be looked at further down the line towards Npgsql 10?

@roji
Copy link
Member

roji commented Mar 14, 2025

@kerams we don't generally do minor releases - yeah, this will have to wait for 10.

@kerams
Copy link

kerams commented Sep 22, 2025

Bump. .NET 10 (and supposedly npgsql) is around the corner and I'd hate to see this going to waste for another year.

Copy link
Contributor

@vonzshik vonzshik left a comment

Choose a reason for hiding this comment

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

In general, looks good enough. Just a few things.

@manandre
Copy link
Collaborator Author

The new multiplexing tests are randomly failing in local (often) and in CI (sometimes).
It seems to happen when an extra "connection open" tracing activity is added when initiating a copy operation.
Any clue on a possible explanation?

@vonzshik
Copy link
Contributor

The new multiplexing tests are randomly failing in local (often) and in CI (sometimes).
It seems to happen when an extra "connection open" tracing activity is added when initiating a copy operation.
Any clue on a possible explanation?

Ye, I do have an idea. You have another query just before initiating COPY, and with multiplexing there is a race between a reader from that query being disposed (this is when we signal the connector that it's free to handle another query) and starting COPY operation. Specifically, the issue is that after the reader is disposed, connector first checks whether it has other queries, and if there are none, then it returns to the pool. But because it races with COPY, what happens is that that connector is not yet in the pool and so for COPY we create another connector. Limiting the pool size to 1 should do the trick.

@manandre
Copy link
Collaborator Author

Limiting the pool size to 1 should do the trick.

I tried, but the test hangs while renting a new connector.

I have found another solution, by setting EnablePhysicalOpenTracing to false.

Copy link
Contributor

@vonzshik vonzshik left a comment

Choose a reason for hiding this comment

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

@manandre thank you and I'm sorry for making you wait for my feedback. Overall looks good, mostly just a few small changes.
Now, the main issue is probably with callbacks, as I imagine people would prefer to at least have an ability to disable tracing. With us prioritizing the release of Npgsql 10 this week, one potential way we can go is we merge this PR as is and I'll add tracing and callbacks to other COPY operations in a separate PR (so as to not force you to work overtime due to me being busy with other stuff).

Comment on lines 342 to 343
// We're not interested in temp table creation's activity
Assert.That(activities.Count, Is.EqualTo(1));
activities.Clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add another callback, to disable both physical tracing and queries?

@manandre
Copy link
Collaborator Author

@vonzshik FYI I have already prepared a branch to instrument other COPY operations.
See main...manandre:npgsql:otel-text

@vonzshik
Copy link
Contributor

vonzshik commented Nov 18, 2025

@vonzshik FYI I have already prepared a branch to instrument other COPY operations. See main...manandre:npgsql:otel-text

@manandre that's actually great! While I didn't check every single thing, overall it seems quite good. Main thing left there is it add callbacks to NpgsqlTracingOptionsBuilder. Overall that should be 3 more callbacks, one for enrichment, one for span name and one for filtering. To differentiate between different copy operations we'll use an enum. So something like:

public enum CopyOperationType
{
    BinaryImport,
    BinaryExport,
    TextImport,
    TextExport,
    RawBinary
}

public NpgsqlTracingOptionsBuilder ConfigureCopyOperationFilter(Func<string, CopyOperationType, bool>? copyOperationFilter)
{
	// TODO
	return this;
}

public NpgsqlTracingOptionsBuilder ConfigureCopyOperationEnrichmentCallback(Action<Activity, string, CopyOperationType>? copyOperationEnrichmentCallback)
{
	// TODO
	return this;
}

public NpgsqlTracingOptionsBuilder ConfigureCopyOperationSpanNameProvider(Func<string, CopyOperationType, string?>? copyOperationSpanNameProvider)
{
	// TODO
	return this;
}

UPD: discussed with @roji, we probably do not want enum at all, so just 3 callbacks and reuse them for every COPY operation.

@roji
Copy link
Member

roji commented Nov 19, 2025

@manandre as we'd like to release Npgsql 10, I think I'll take over this PR to bring it to completion ASAP (unless I run into issues). Can you please comment here in the next couple hours if you're available to do work on it?

@manandre
Copy link
Collaborator Author

manandre commented Nov 19, 2025

@roji I am on it, I have already implemented the new callbacks, I still have to add an unit test.
I have just pushed my latest changes.
I have planned to continue working on it this evening. But feel free to work on it if you need it to be done on shorter term.
Keep me posted!

@kerams
Copy link

kerams commented Nov 19, 2025

Thank you, sirs.

@roji
Copy link
Member

roji commented Nov 19, 2025

@manandre I think this is almost the last thing left that we want to get in for 10. Let me know where you're at and how you'd like to finish this - I'll get a bit to eat and will be back in ~1 hour to review etc.

@manandre
Copy link
Collaborator Author

Unit test added.
@roji Do you want I add other copy operations in this PR or in another one?

@roji
Copy link
Member

roji commented Nov 19, 2025

Let's wrap everything up in this single PR. It's very likely we'll be releasing Npgsql 10.0, I'll be available from the morning to review and iterate over it.

@manandre
Copy link
Collaborator Author

@roji Everything added and rebased on latest main branch

roji
roji previously requested changes Nov 20, 2025
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Hey @manandre, thanks for the quick work. Here's a batch of comments - let me know what you're availability is like. We absolutely want to release Npgsql 10.0 today, if you're not available I might take over the PR, or we may defer it.

@manandre
Copy link
Collaborator Author

@roji I am not available before this evening. You can take it over.

@roji
Copy link
Member

roji commented Nov 20, 2025

FYI am starting to work on this now.

@roji roji force-pushed the otel-binary branch 3 times, most recently from 97bdbc6 to 3308f81 Compare November 21, 2025 17:24
@manandre
Copy link
Collaborator Author

manandre commented Nov 21, 2025

await using var dataSource = CreateDataSource(ds => ds.ConfigureTracing(o => o.EnablePhysicalOpenTracing(false)));

@roji It must be applied in all copy tests to avoid random failures.

Copy link
Contributor

@vonzshik vonzshik left a comment

Choose a reason for hiding this comment

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

Looks good, I think? Just have to look at test failures.

@roji
Copy link
Member

roji commented Nov 22, 2025

It must be applied in all copy tests to avoid random failures.

@manandre you're right, I forgot about multiplexing when working on the tests.

@roji roji enabled auto-merge (squash) November 22, 2025 08:34
@roji roji dismissed their stale review November 22, 2025 08:36

Took over PR and applied changes.

@roji roji merged commit 4f4fe19 into npgsql:main Nov 22, 2025
23 of 24 checks passed
@manandre manandre deleted the otel-binary branch November 22, 2025 09:21
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.

Instrument NpgsqlBinaryImporter for OTel tracing

5 participants