Skip to content

Add exception tag in DefaultMongoCommandTagsProvider #4978

Open
@hadjiski

Description

@hadjiski

Other metrics appear to have default error/exception tags, the mongodb.driver.commands one not.
Even though a throwable is defined in the CommandFailedEvent it is not utilized for the default tags:

    @Override
    public void commandSucceeded(CommandSucceededEvent event) {
        timeCommand(event, event.getElapsedTime(TimeUnit.NANOSECONDS));
    }

    @Override
    public void commandFailed(CommandFailedEvent event) {
        timeCommand(event, event.getElapsedTime(TimeUnit.NANOSECONDS));
    }

    private void timeCommand(CommandEvent event, long elapsedTimeInNanoseconds) {
        Timer.builder("mongodb.driver.commands")
            .description("Timer of mongodb commands")
            .tags(tagsProvider.commandTags(event))
            .register(registry)
            .record(elapsedTimeInNanoseconds, TimeUnit.NANOSECONDS);
    }
@Override
    public Iterable<Tag> commandTags(CommandEvent event) {
        return Tags.of(Tag.of("command", event.getCommandName()),
                Tag.of("collection", getAndRemoveCollectionNameForCommand(event)),
                Tag.of("cluster.id",
                        event.getConnectionDescription().getConnectionId().getServerId()
                   .getClusterId().getValue()),
                Tag.of("server.address", event.getConnectionDescription()
                .getServerAddress().toString()),
                Tag.of("status", (event instanceof CommandSucceededEvent) 
? "SUCCESS" : "FAILED"));
    }

Other standard metrics like spring.data.repository.invocations, http.server/client.requests on the other hand are having the error/exception as default, e.g. spring's DefaultRepositoryTagsProvider:

public Iterable<Tag> repositoryTags(RepositoryMethodInvocationListener.RepositoryMethodInvocation invocation) {
        Tags tags = Tags.empty();
        tags = this.and(tags, invocation.getRepositoryInterface(), "repository", this::getSimpleClassName);
        tags = this.and(tags, invocation.getMethod(), "method", Method::getName);
        tags = this.and(tags, invocation.getResult().getState(), "state", Enum::name);
        tags = this.and(tags, invocation.getResult().getError(), "exception",
                      this::getExceptionName, EXCEPTION_NONE);
        return tags;
    }

I see that exception is a custom tag name, which is used by spring and error appears to be the one from micrometer, and in the end it does not matter, both or either one would be fine, but none of them appears kind of missing.
As a workaround, I could define my custom tag provider and push the tag myself whenever the event is of type CommandFailedEvent (for the time being), but out of the box here would be more feasible in my eyes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementA general enhancementinstrumentationAn issue that is related to instrumenting a componentmodule: micrometer-coreAn issue that is related to our core module

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions