use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class EcsResourceTest method testCreateAttributes.
@Test
void testCreateAttributes() throws UnknownHostException {
when(mockDockerHelper.getContainerId()).thenReturn("0123456789A");
Map<String, String> mockSysEnv = new HashMap<>();
mockSysEnv.put(ECS_METADATA_KEY_V3, "ecs_metadata_v3_uri");
Resource resource = EcsResource.buildResource(mockSysEnv, mockDockerHelper);
Attributes attributes = resource.getAttributes();
assertThat(resource.getSchemaUrl()).isEqualTo(ResourceAttributes.SCHEMA_URL);
assertThat(attributes).containsOnly(entry(ResourceAttributes.CLOUD_PROVIDER, "aws"), entry(ResourceAttributes.CLOUD_PLATFORM, "aws_ecs"), entry(ResourceAttributes.CONTAINER_NAME, InetAddress.getLocalHost().getHostName()), entry(ResourceAttributes.CONTAINER_ID, "0123456789A"));
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class LambdaResourceTest method shouldNotCreateResourceForNotLambda.
@Test
void shouldNotCreateResourceForNotLambda() {
Attributes attributes = LambdaResource.buildResource(emptyMap()).getAttributes();
assertThat(attributes).isEmpty();
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class LambdaResourceTest method shouldAddNonEmptyAttributes.
@Test
void shouldAddNonEmptyAttributes() {
Resource resource = LambdaResource.buildResource(singletonMap("AWS_LAMBDA_FUNCTION_NAME", "my-function"));
Attributes attributes = resource.getAttributes();
assertThat(resource.getSchemaUrl()).isEqualTo(ResourceAttributes.SCHEMA_URL);
assertThat(attributes).containsOnly(entry(ResourceAttributes.CLOUD_PROVIDER, "aws"), entry(ResourceAttributes.CLOUD_PLATFORM, "aws_lambda"), entry(ResourceAttributes.FAAS_NAME, "my-function"));
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class BeanstalkResourceTest method testConfigFileMissing.
@Test
void testConfigFileMissing() {
Attributes attributes = BeanstalkResource.buildResource("a_file_never_existing").getAttributes();
assertThat(attributes).isEmpty();
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class Ec2ResourceTest method imdsv1.
@Test
void imdsv1() {
server.enqueue(HttpResponse.of(HttpStatus.NOT_FOUND));
server.enqueue(HttpResponse.of(MediaType.JSON_UTF_8, IDENTITY_DOCUMENT));
server.enqueue(HttpResponse.of("ec2-1-2-3-4"));
Resource resource = Ec2Resource.buildResource("localhost:" + server.httpPort());
assertThat(resource.getSchemaUrl()).isEqualTo(ResourceAttributes.SCHEMA_URL);
Attributes attributes = resource.getAttributes();
assertThat(attributes).containsOnly(entry(ResourceAttributes.CLOUD_PROVIDER, "aws"), entry(ResourceAttributes.CLOUD_PLATFORM, "aws_ec2"), entry(ResourceAttributes.HOST_ID, "i-1234567890abcdef0"), entry(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "us-west-2b"), entry(ResourceAttributes.HOST_TYPE, "t2.micro"), entry(ResourceAttributes.HOST_IMAGE_ID, "ami-5fb8c835"), entry(ResourceAttributes.CLOUD_ACCOUNT_ID, "123456789012"), entry(ResourceAttributes.CLOUD_REGION, "us-west-2"), entry(ResourceAttributes.HOST_NAME, "ec2-1-2-3-4"));
AggregatedHttpRequest request1 = server.takeRequest().request();
assertThat(request1.path()).isEqualTo("/latest/api/token");
assertThat(request1.headers().get("X-aws-ec2-metadata-token-ttl-seconds")).isEqualTo("60");
AggregatedHttpRequest request2 = server.takeRequest().request();
assertThat(request2.path()).isEqualTo("/latest/dynamic/instance-identity/document");
assertThat(request2.headers().get("X-aws-ec2-metadata-token")).isNull();
}
Aggregations