Provider better APIs to move between Instrument Tags and Commons Tags (original) (raw)

When defining a custom Observation, you get exposed to Commons TagKey...

enum MongoObservation implements DocumentedObservation { }

This makes it tricky to use them in meter-based assertions like this:

@Test void successfullyCompletedCommandWithoutClusterInformationShouldCreateTimerWhenParentSampleInRequestContext() {

// given
Observation parent = Observation.start("name", observationRegistry);
TestRequestContext testRequestContext = TestRequestContext.withObservation(parent);

// when
listener.commandStarted(new CommandStartedEvent(testRequestContext, 0, null, "database", "insert",
        new BsonDocument("collection", new BsonString("user"))));
listener.commandSucceeded(new CommandSucceededEvent(testRequestContext, 0, null, "insert", null, 0));

// then
assertThat(meterRegistry).hasTimerWithNameAndTags(HighCardinalityCommandTags.MONGODB_COMMAND.getKey(),
        Tags.of(Tag.of(LowCardinalityCommandTags.MONGODB_COLLECTION.getKey(), "user")));

}

Instead, you are forced to "convert" from one to the other.

If Commons Tags are, well, common, why can't Micrometer Tracing use them? Isn't that the point of a "common"?