Skip to content

Conversation

@birschick-bq
Copy link
Contributor

Provides an virtual override for GetActivitySourceTags(properties) to retrieve tags when creating the ActivitySource.
Also adds the ActivitySourceName property so an ActivityListener can create a useful filter.

@github-actions github-actions bot added this to the ADBC Libraries 20 milestone Jul 29, 2025
@birschick-bq
Copy link
Contributor Author

@jadewang-db @jeremytang-db
Please review when you have a chance. Thanks.

@jeremytang-db
Copy link

So the idea is to be able to do something like this?
ShouldListenTo = (activitySource) => activitySource.Tags["Hosturl"] = "abc.databricks.com"
If there are mulitple instances of DatabricksConnection with the same combination of tags, wouldn't all the listeners pick up on all the activities?

@birschick-bq
Copy link
Contributor Author

So the idea is to be able to do something like this? ShouldListenTo = (activitySource) => activitySource.Tags["Hosturl"] = "abc.databricks.com" If there are mulitple instances of DatabricksConnection with the same combination of tags, wouldn't all the listeners pick up on all the activities?

@jeremytang-db

One option is to start a new Listeners for each connection - in which case, you would just use a new Guid for each connection/listener combo.

Or, more complicated is that you hash the connection/token to produce a unique reproduceable value that represents the Id and only start a new Listener when that Id doesn't already exist. But this will be more complicated in the Dispose() code to ensure the last source won't send any more messages.

this.SourceId = CalculateSourceId(properties);
...
ShouldListenTo = (activitySource) => 
    activitySource.Tags.Any(t => t.Key == "DatabricksSourceId" && t.Value?.Equals(this.SourceId) == true)

@jeremytang-db
Copy link

@birschick-bq
So if I understand correctly, for the first approach:

  1. Each connection generates a GUID
  2. Add the GUID to the ActivitySource tags
  3. Each connection creates a Listener and passes their own GUID to it
  4. Each listener checks for the GUID in the activitySource tags to listen to

@birschick-bq
Copy link
Contributor Author

@birschick-bq So if I understand correctly, for the first approach:

  1. Each connection generates a GUID
  2. Add the GUID to the ActivitySource tags
  3. Each connection creates a Listener and passes their own GUID to it
  4. Each listener checks for the GUID in the activitySource tags to listen to

That is correct. This filters out any messages not generated by your connection. And ShouldListenTo is not called for every Activity, but two times for each ActivitySource (==TracingConnection).

The ActivityListener can be instantiated inside the Connection and be disposed when the connection disposes.

/// <param name="activitySourceVersion">The version of the component publishing the tracing info.</param>
/// <param name="traceParent">The trace parent context, which is used to link the activity to a distributed trace.</param>
/// <param name="tags">The tags associated with the activity.</param>
public ActivityTrace(string? activitySourceName = default, string? activitySourceVersion = default, string? traceParent = default, IEnumerable<KeyValuePair<string, object?>>? tags = default)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a binary breaking change. Was this class already part of the last release? If we had "declared 1.0" and already included this class in a public release then we'd want to add an overload instead of changing the signature. (As we are not yet at 1.0, I think it's probably okay not to worry about binary compatibility in this case.)

@CurtHagenlocher CurtHagenlocher merged commit 17b6ca9 into apache:main Jul 31, 2025
7 checks passed
@birschick-bq birschick-bq deleted the dev/birschick-bq/activity-source-tags branch August 13, 2025 20:05
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