Skip to content

Commit

Permalink
Update resource passed for e2e-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 committed Nov 16, 2023
1 parent 21b896b commit 292a6d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion e2e-test-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
implementation platform(libraries.opentelemetry_bom)
implementation project(':exporter-trace')
implementation project(':propagators-gcp')
runtimeOnly project(':detector-resources')
implementation project(':detector-resources')
}

tasks.build.dependsOn tasks.shadowJar
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.cloud.opentelemetry.endtoend;

import com.google.cloud.opentelemetry.detectors.GCPResource;
import com.google.cloud.opentelemetry.propagators.XCloudTraceContextPropagator;
import com.google.cloud.opentelemetry.trace.TraceConfiguration;
import com.google.cloud.opentelemetry.trace.TraceExporter;
Expand All @@ -40,6 +41,7 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.logging.Logger;

Expand All @@ -66,7 +68,7 @@ private Response health(Request request) {

/** Basic trace test. */
private Response basicTrace(Request request) {
LOGGER.info("Running basicTrace test, request: " + request);
LOGGER.info("Running basicTrace test, request: " + request.toString());
return withTemporaryTracer(
(tracer) -> {
Span span =
Expand All @@ -75,6 +77,7 @@ private Response basicTrace(Request request) {
.setAttribute(Constants.TEST_ID, request.testId())
.startSpan();
try {
LOGGER.info("Sending trace with ID: " + span.getSpanContext().getTraceId());
return Response.ok(Map.of(Constants.TRACE_ID, span.getSpanContext().getTraceId()));
} finally {
span.end();
Expand All @@ -84,11 +87,17 @@ private Response basicTrace(Request request) {

/** Test where we include resource detection */
private Response detectResource(Request request) {
LOGGER.info("Running detectResource test, request: " + request);
LOGGER.info("Running detectResource test, request: " + request.toString());
Resource gcpResource =
new GCPResource()
.createResource(
DefaultConfigProperties.create(
Map.of("otel.traces.exporter", "none", "otel.metrics.exporter", "none")));
Resource resource =
ResourceConfiguration.createEnvironmentResource(
DefaultConfigProperties.create(
Map.of("otel.traces.exporter", "none", "otel.metrics.exporter", "none")));
Resource.getDefault()
.merge(gcpResource)
.merge(ResourceConfiguration.createEnvironmentResource());

return withTemporaryOtel(
resource,
(sdk) -> {
Expand Down Expand Up @@ -210,10 +219,12 @@ private static OpenTelemetrySdk setupTraceExporter(Resource resource) throws IOE
TraceConfiguration configuration =
TraceConfiguration.builder()
.setDeadline(Duration.ofMillis(30000))
.setProjectId(Constants.PROJECT_ID != "" ? Constants.PROJECT_ID : null)
.setProjectId(!Objects.equals(Constants.PROJECT_ID, "") ? Constants.PROJECT_ID : null)
.build();

SpanExporter traceExporter = TraceExporter.createWithConfiguration(configuration);

LOGGER.info("Setting up tracer provider with resource " + resource.getAttributes());
// Register the TraceExporter with OpenTelemetry
return OpenTelemetrySdk.builder()
.setPropagators(
Expand Down

0 comments on commit 292a6d9

Please sign in to comment.