Skip to content

Commit

Permalink
add host.name and container.id to micrometer tags (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk authored Apr 12, 2022
1 parent 3a555d9 commit 3c9fe3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

package com.splunk.opentelemetry.micrometer;

import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.CONTAINER_ID;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.DEPLOYMENT_ENVIRONMENT;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.HOST_NAME;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.PROCESS_PID;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.PROCESS_RUNTIME_NAME;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME;

import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -37,11 +43,13 @@ Tags build() {
addTag(
globalTags,
"deployment.environment",
ResourceAttributes.DEPLOYMENT_ENVIRONMENT,
DEPLOYMENT_ENVIRONMENT,
AttributeKey.stringKey("environment"));
addTag(globalTags, "service", ResourceAttributes.SERVICE_NAME);
addTag(globalTags, "runtime", ResourceAttributes.PROCESS_RUNTIME_NAME);
addTag(globalTags, "process.pid", ResourceAttributes.PROCESS_PID);
addTag(globalTags, "service", SERVICE_NAME);
addTag(globalTags, "runtime", PROCESS_RUNTIME_NAME);
addTag(globalTags, PROCESS_PID.getKey(), PROCESS_PID);
addTag(globalTags, CONTAINER_ID.getKey(), CONTAINER_ID);
addTag(globalTags, HOST_NAME.getKey(), HOST_NAME);
return Tags.of(globalTags);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,25 @@ void shouldBuildGlobalTagsList() {
ResourceAttributes.PROCESS_RUNTIME_NAME,
"OpenJDK Runtime Environment",
ResourceAttributes.PROCESS_PID,
12345L));
12345L,
ResourceAttributes.HOST_NAME,
"astronaut",
ResourceAttributes.CONTAINER_ID,
"abcd90210"));

// when
var tags = new GlobalTagsBuilder(resource).build();

// then
assertThat(tags.stream())
.hasSize(4)
.hasSize(6)
.containsExactlyInAnyOrder(
Tag.of("deployment.environment", "prod"),
Tag.of("service", "my-service"),
Tag.of("runtime", "OpenJDK Runtime Environment"),
Tag.of("process.pid", "12345"));
Tag.of("process.pid", "12345"),
Tag.of("host.name", "astronaut"),
Tag.of("container.id", "abcd90210"));
}

@Test
Expand Down

0 comments on commit 3c9fe3c

Please sign in to comment.