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

Customize observation spans #4321

Closed
cmergenthaler opened this issue Mar 8, 2023 · 1 comment
Closed

Customize observation spans #4321

cmergenthaler opened this issue Mar 8, 2023 · 1 comment
Assignees
Labels
type: enhancement A general enhancement

Comments

@cmergenthaler
Copy link

cmergenthaler commented Mar 8, 2023

Event though the observationConvention already includes some good tags in the spans, I need to add some additional custom tags to it. Unfortunately, I did not find an easy way to customize the observation spans, because the usage of MongoHandlerObservationConvention is hardcoded:
https://github.com/spring-projects/spring-data-mongodb/blob/main/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/observability/MongoObservationCommandListener.java#L110

So the only way would be to implement my own MongoHandlerObservationConvention (as we are not able to override the DefaultMongoHandlerObservationConvention) and in addition to override MongoObservationCommandListener and rewrite the whole commandStarted method to use my custom observationConvention. In addition, we also need to implement our own SenderContext as the MongoHandlerContext is not public. Then I can use it in the bean-definition of MongoClientSettingsBuilderCustomizer by setting

@Bean
public MongoClientSettingsBuilderCustomizer mongoMetricsSynchronousContextProvider(ObservationRegistry registry) {
    return (clientSettingsBuilder) -> {
        clientSettingsBuilder.contextProvider(ContextProviderFactory.create(registry))
                .addCommandListener(new MyCustomMongoObservationCommandListener(registry));
    };
}

But that's actually a lot of effort just to be able to add a custom tag to the spans.
Maybe it would be easier to allow us overriding the DefaultMongoHandlerObservationConvention and use a bean-definition of MongoHandlerObservationConvention or provide a setter in MongoObservationCommandListener to set the actual used MongoHandlerObservationConvention.

@cmergenthaler
Copy link
Author

@gregturn @christophstrobl Hey, are there any updates? Am I missing something here?

francoiskha added a commit to francoiskha/spring-data-mongodb that referenced this issue Jan 10, 2024
francoiskha added a commit to francoiskha/spring-data-mongodb that referenced this issue Jan 10, 2024
francoiskha added a commit to francoiskha/spring-data-mongodb that referenced this issue Jan 10, 2024
francoiskha added a commit to francoiskha/spring-data-mongodb that referenced this issue Jan 10, 2024
@christophstrobl christophstrobl added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 8, 2024
@christophstrobl christophstrobl added this to the 4.3 M1 (2024.0.0) milestone Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants