Search in sources :

Example 1 with Resource

use of io.opentelemetry.sdk.resources.Resource in project inspectit-ocelot by inspectIT.

the class OpenTelemetryProtoConverter method toSpanData.

/**
 * @return Converts an {@link InstrumentationLibrarySpans} instance to a stream of individual {@link SpanData} instances.
 */
private Stream<SpanData> toSpanData(InstrumentationLibrarySpans librarySpans, Resource resource, Map<String, String> customSpanAttributes) {
    InstrumentationLibrary library = librarySpans.getInstrumentationLibrary();
    InstrumentationLibraryInfo libraryInfo = InstrumentationLibraryInfo.create(library.getName(), library.getVersion());
    return librarySpans.getSpansList().stream().map(protoSpan -> OcelotSpanUtils.createSpanData(protoSpan, resource, libraryInfo, customSpanAttributes)).filter(Objects::nonNull);
}
Also used : java.util(java.util) RequestUtils(rocks.inspectit.oce.eum.server.utils.RequestUtils) ImmutableMap(com.google.common.collect.ImmutableMap) Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) Autowired(org.springframework.beans.factory.annotation.Autowired) Supplier(java.util.function.Supplier) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) EumServerConfiguration(rocks.inspectit.oce.eum.server.configuration.model.EumServerConfiguration) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) HttpServletRequest(javax.servlet.http.HttpServletRequest) Stream(java.util.stream.Stream) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) OcelotSpanUtils(io.opentelemetry.sdk.trace.OcelotSpanUtils) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) SpanData(io.opentelemetry.sdk.trace.data.SpanData) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary)

Example 2 with Resource

use of io.opentelemetry.sdk.resources.Resource 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"));
}
Also used : HashMap(java.util.HashMap) Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 3 with Resource

use of io.opentelemetry.sdk.resources.Resource 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"));
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 4 with Resource

use of io.opentelemetry.sdk.resources.Resource 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();
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) Test(org.junit.jupiter.api.Test)

Example 5 with Resource

use of io.opentelemetry.sdk.resources.Resource in project opentelemetry-java by open-telemetry.

the class BeanstalkResourceTest method testCreateAttributes.

@Test
void testCreateAttributes(@TempDir File tempFolder) throws IOException {
    File file = new File(tempFolder, "beanstalk.config");
    String content = "{\"noise\": \"noise\", \"deployment_id\":4,\"" + "version_label\":\"2\",\"environment_name\":\"HttpSubscriber-env\"}";
    Files.write(content.getBytes(Charsets.UTF_8), file);
    Resource resource = BeanstalkResource.buildResource(file.getPath());
    Attributes attributes = resource.getAttributes();
    assertThat(attributes).containsOnly(entry(ResourceAttributes.CLOUD_PROVIDER, "aws"), entry(ResourceAttributes.CLOUD_PLATFORM, "aws_elastic_beanstalk"), entry(ResourceAttributes.SERVICE_INSTANCE_ID, "4"), entry(ResourceAttributes.SERVICE_VERSION, "2"), entry(ResourceAttributes.SERVICE_NAMESPACE, "HttpSubscriber-env"));
    assertThat(resource.getSchemaUrl()).isEqualTo(ResourceAttributes.SCHEMA_URL);
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

Resource (io.opentelemetry.sdk.resources.Resource)99 Test (org.junit.jupiter.api.Test)82 Attributes (io.opentelemetry.api.common.Attributes)58 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)44 TestClock (io.opentelemetry.sdk.testing.time.TestClock)40 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)39 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)39 Duration (java.time.Duration)39 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)33 Meter (io.opentelemetry.api.metrics.Meter)31 OperationUpdater (io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater)24 PointData (io.opentelemetry.sdk.metrics.data.PointData)24 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)24 LogCapturer (io.github.netmikey.logunit.api.LogCapturer)16 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)16 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)16 InstrumentType (io.opentelemetry.sdk.metrics.common.InstrumentType)15 Aggregation (io.opentelemetry.sdk.metrics.view.Aggregation)15 InstrumentSelector (io.opentelemetry.sdk.metrics.view.InstrumentSelector)15 View (io.opentelemetry.sdk.metrics.view.View)15