Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #1297 - Add exporter services and their registration with OpenTelemetry #1375

Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
2a2f501
Initial commit of the ActionMetricsRecorder that records metrics of I…
Nov 16, 2021
2439161
Removed unused code from ActionsMetricsRecorder
Nov 16, 2021
cae483c
The state of the ActionsMetricsRecorder now also depends on the maste…
Nov 18, 2021
1e79210
improved implementation of ActionMetricsRecorder
Nov 18, 2021
653f717
Removed log statements
Nov 19, 2021
38f59df
Merge remote-tracking branch 'upstream/master' into features/feat-123…
Nov 24, 2021
a10487a
Fixed broken tests in MethodHookTest and MethodHoodGeneratorTest. Rem…
Nov 25, 2021
309f621
Refactored BoundGenericAction#getName to only return the action's nam…
Nov 25, 2021
50d25a8
Upgraded OpenCensus to v0.28.3
Nov 29, 2021
6f74fe0
Changed gson version to v2.8.5 to work with checkDependencyJavaVersions
Nov 30, 2021
4546f22
Started the integration of the OpenCensus-OpenTelemetry-Bridge (i.e.,…
Dec 10, 2021
6ebb784
Fixed small typo in LoggingExporterService
Dec 10, 2021
ce3c09d
Update LoggingExporterServiceTest.java
Dec 10, 2021
2bc438f
Minor refactoring (renaming) of classes
Dec 10, 2021
b6b94ff
Refactored the LoggingExporterService that combined the export of tra…
Dec 10, 2021
a155806
Excluded OpenTelemetry and Jackson from the dependency check.
Dec 10, 2021
dd4fe69
Merge remote-tracking branch 'upstream/master' into feat-1246-integra…
Dec 10, 2021
537fdcc
Fixed WriteSpanAttributesTest when using the opencensus-shim
Dec 10, 2021
2e95276
Fixed SetSpanStatusActionTest when using the opencensus-shim
Dec 10, 2021
3a54584
Minor refactoring of method names in LoggingMetricsExporterServiceTes…
Dec 10, 2021
45661c7
Adjusted the systemTests in the agent package to work with OpenTeleme…
Dec 16, 2021
ad5a2bb
Merge remote-tracking branch 'inspectIT/master' into features/feat-12…
mariusoe Dec 23, 2021
f6d8944
Small refactoring and cleanup
mariusoe Dec 23, 2021
d03b5c9
Updated documentation and default configuration
mariusoe Dec 23, 2021
3dfcc5b
Fix recorder tests
mariusoe Dec 23, 2021
9ea22c1
Implemented the concurrent support of io.opentelemetry.context.Contex…
Jan 7, 2022
632a3fa
Fixed tests in TraceSettingsTest by adjusting the span's expected sta…
Jan 7, 2022
66ee94a
Minor adjustments in ReflectionUtils and OpenCensusShimUtils
Jan 7, 2022
02cf139
Disabled tests that will not work until CustomSpanBuilder is fixed fo…
Jan 7, 2022
ab1309d
Fix tests and typo in docs
mariusoe Jan 10, 2022
6cc58a7
Fixed the HttpRemoteTracingTest by adjusting StackTraceSampler#create…
Jan 11, 2022
5853efa
Added a stricter checker to ensure OTEL scopes are closed on the corr…
Jan 11, 2022
0326626
Minor adjustments in ReflectionUtils
Jan 11, 2022
977d3cb
Removed obsolete TODO note from HttpRemoteTracingTest and adjusted a …
Jan 11, 2022
61baa64
Disabled tests for service exporters that are not supported with the …
Jan 11, 2022
a65e278
Minor refactoring of LoggingMetricExporterService and LoggingTraceExp…
Jan 11, 2022
37bdc0a
#1269: Integrated the concept of an IOpenTelemetryController that han…
Jan 11, 2022
6c98197
Removed unused classes (#1246)
Jan 11, 2022
d25a6a0
Removed OpenCensusAgentMetricsExporterService and OpenCensusAgentTrac…
Jan 11, 2022
8bce963
Updated the documentation of metric-exporters.md and trace-exporters.…
Jan 11, 2022
1496b79
Updated breaking-changes.md (#1246)
Jan 11, 2022
6de9e44
Added documentation for OpenTelemetry configuration in open-telemetry…
Jan 11, 2022
d51c3f3
Refactored LoggingMetricExporterService and LoggingTraceExporterServi…
Jan 11, 2022
fc546bf
Merge branch 'features/feat-1231-self-monitoring' into feat-1246-inte…
Jan 11, 2022
34f6306
Fixed failing tests in ModelAutoCompleterTest (#1246)
Jan 11, 2022
1ed44c5
Merge remote-tracking branch 'origin/feat-1246-integrate-oc-otel-brid…
Jan 12, 2022
4b20a8b
#1269: Changed OpenTelemetryControllerImpl to not rebuild the SdkTrac…
Jan 13, 2022
108cb31
#1269: Added tests to test tracing configuration in OpenTelemetryCont…
Jan 13, 2022
e4c3fd3
#1269: Fixed initialization of OpenTelemetry in Log4J2TraceIdAutoInje…
Jan 13, 2022
7f20156
#1269: Added tests to test metrics (meter provider) configuration in …
Jan 13, 2022
ffe5796
#1269: Moved DynamicMultiSpanExporter
Jan 13, 2022
1ed7744
#1269: Removed OpenCensusAgentMetricsExporterSettings.java and OpenCe…
Jan 17, 2022
2f408ac
#1269: Ad: Removed OpenCensusAgentMetricsExporterSettings.java and Op…
Jan 17, 2022
0626326
#1269: Added new properties to TracingSettings (considering batch spa…
Jan 17, 2022
4d0ad54
#1269: Removed the serviceName property from JaegerExporterSettings, …
Jan 17, 2022
f07db85
#1269: Removed the SpringTestBase.yml and moved the properties to Spr…
Jan 17, 2022
8a826dc
#1269: Fixed InfluxExporterServiceIntTest
Jan 17, 2022
6e555bd
#1269: Minor refactoring (removed unnecessary logs, added TestPropert…
Jan 17, 2022
0099124
#1269: Slimmed down OpenTelemetryControllerImpl
Jan 17, 2022
0fdac4b
#1269: Replaced calls to OpenCensusUtils#flushSpanExporter with Insta…
Jan 18, 2022
8ff8bd6
#1269: Renamed OtlpTraceExporterService to OtlpGrpcTraceExporterServi…
Jan 18, 2022
0a010bc
#1269: Fixed OtlpGrpcTraceExporterService to use "otlGrpc" instead of…
Jan 18, 2022
a099027
#1279: Upgraded OTEL to v1.10.0, refactored OpenTelemetryControllerIm…
Jan 25, 2022
a7f915b
#1279: Removed unused classes and comments/TODO statements
Jan 31, 2022
e57ac2a
#1279: Added test cases to OpenTelemetryControllerImplTest
Feb 1, 2022
a32ad6f
#1279: Minor refactoring.
Feb 1, 2022
50b056a
#1297: started implementing JaegerGrpcExporterService and started wor…
Feb 8, 2022
943ba81
feat(open-telemetry): [#1297] add test base for exporter service inte…
Mar 9, 2022
762553d
feat(open-telemetry): [#1297] improve test base for exporter service …
Mar 10, 2022
b55673b
feat(open-telemetry): [#1297] remove unused ContextPropagators
Mar 14, 2022
711b254
merge remote tracking branch 'inspectIT/feature/opentelemetry-migrati…
Mar 16, 2022
eb7f102
feat(open-telemetry): [#1297] update the `enabled` flag of metrics/tr…
Mar 16, 2022
f9e4467
feat(open-temeletry): [#1297] add `SLF4JBridgeHandlerUtils` to (un-)i…
Mar 16, 2022
2663b9a
feat(open-telemetry): [#1297] add `defaultSettings` tests to OTLP and…
Mar 16, 2022
54e30cf
feat(open-telemetry): [#1297] remove unused `ContextPropagators` in `…
Mar 16, 2022
731616a
feat(open-telemetry): [#1297] add integration test for OpenTelemetryC…
Mar 17, 2022
ca6e3be
feat(exporter): [#1297] rename `url` property of exporters to `endpoi…
Mar 25, 2022
bbb740f
feat(eum): [#1297] replace `grpc` property in `application.yml` and …
Mar 28, 2022
25d4035
Merge remote-tracking branch 'inspectIT-ocelot/feature/opentelemetry-…
Mar 28, 2022
560b1a6
Merge remote-tracking branch 'inspectIT-ocelot/feature/opentelemetry-…
Mar 30, 2022
d2eff03
feat(config): [#1297] keep deprecated property `grpc` and automatical…
Apr 13, 2022
b63b529
fix(otel): implemented changes requested in the pull request
May 5, 2022
204042a
fix(validation): refactor transport protocol validation
May 5, 2022
624f115
Merge branch 'feature/opentelemetry-migration' into features/feat-129…
mariusoe May 11, 2022
6611bd8
Small refactorings
mariusoe May 11, 2022
f538ce4
temporarily adding otel migration branch to ci build
mariusoe May 11, 2022
0eac28e
Set Wiremock to use localhost
May 12, 2022
69cd568
refactored final modifier removal in jdk12+
mariusoe May 13, 2022
92e0773
fix tests for jdk +12
mariusoe May 13, 2022
4db1e60
Update HighPrecisionTimerTest to use await().atLeast()
May 13, 2022
c6e8044
Update HighPrecisionTimerTest to use await().atLeast()
May 13, 2022
60adc37
Merge remote-tracking branch 'upstream/features/feat-1297-integrate-j…
May 13, 2022
82e8b1b
Adjust timeout for HighPrecisionTimerTest
May 13, 2022
5b8c897
refactored highprecisiontimer tests
mariusoe May 13, 2022
ef3f189
fixed breaking changes documentation
mariusoe May 13, 2022
4a544e1
added autotracing availability info to the breaking changes
mariusoe May 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,427 changes: 4,410 additions & 3,017 deletions THIRD-PARTY-LICENSES.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
* Accessor to access specific Git revision/commits. Using this class ensures that all operations will be executed
Expand Down Expand Up @@ -110,7 +113,7 @@ public RevisionAccess getCommonAncestor(RevisionAccess other) {
RevWalk walk = new RevWalk(repository);
walk.setRevFilter(RevFilter.MERGE_BASE);
// RevCommits need to be produced by the same RevWalk instance otherwise it can't compare them
walk.markStart(walk.parseCommit(this.revCommit.toObjectId()));
walk.markStart(walk.parseCommit(revCommit.toObjectId()));
walk.markStart(walk.parseCommit(other.revCommit.toObjectId()));
RevCommit mergeBase = walk.next();

Expand Down Expand Up @@ -186,7 +189,8 @@ protected String verifyPath(String relativeBasePath, String relativePath) throws
Path path = Paths.get(relativePath).normalize();

if (StringUtils.isBlank(relativeBasePath)) {
return path.toString().replace("\\", "/");
// replace '\' with '/'. A regex that matches a single backslash character must include four backslashes, see https://www.gnu.org/software/guile/manual/html_node/Backslash-Escapes.html
return path.toString().replaceAll("\\\\", "/");
}

Path basePath = Paths.get(relativeBasePath).normalize();
Expand All @@ -196,7 +200,8 @@ protected String verifyPath(String relativeBasePath, String relativePath) throws
throw new IllegalArgumentException("User path escapes the base path: " + relativePath);
}

return resolvedPath.toString().replace("\\", "/");
// replace '\' with '/'. A regex that matches a single backslash character must include four backslashes, see https://www.gnu.org/software/guile/manual/html_node/Backslash-Escapes.html
return resolvedPath.toString().replaceAll("\\\\", "/");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ public class InfluxExporterService {
private boolean shouldEnable() {
InfluxExporterSettings influx = configuration.getExporters().getMetrics().getInflux();
if (!influx.getEnabled().isDisabled()) {
if (StringUtils.hasText(influx.getUrl())) {
if (StringUtils.hasText(influx.getEndpoint())) {
return true;
} else if (StringUtils.hasText(influx.getUrl())) {
log.warn("You are using the deprecated property 'url'. This property will be invalid in future releases of InspectIT Ocelot, please use `endpoint` instead.");
return true;
} else if (influx.getEnabled().equals(ExporterEnabledState.ENABLED)) {
log.warn("InfluxDB Exporter is enabled but no url set.");
log.warn("InfluxDB Exporter is enabled but 'endpoint' is not set.");
}
}
return false;
Expand All @@ -59,9 +62,10 @@ private boolean shouldEnable() {
private void doEnable() {
InfluxExporterSettings influx = configuration.getExporters().getMetrics().getInflux();
if (shouldEnable()) {
log.info("Starting InfluxDB Exporter to '{}:{}' on '{}'", influx.getDatabase(), influx.getRetentionPolicy(), influx.getUrl());
String endpoint = StringUtils.hasText(influx.getEndpoint()) ? influx.getEndpoint() : influx.getUrl();
log.info("Starting InfluxDB Exporter to '{}:{}' on '{}'", influx.getDatabase(), influx.getRetentionPolicy(), endpoint);
activeExporter = InfluxExporter.builder()
.url(influx.getUrl())
.url(endpoint)
.database(influx.getDatabase())
.retention(influx.getRetentionPolicy())
.user(influx.getUser())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import rocks.inspectit.ocelot.config.model.exporters.trace.TraceExportersSettings;

import javax.annotation.PostConstruct;
import javax.validation.Valid;
import java.util.Optional;

@Configuration
Expand All @@ -33,23 +34,23 @@ public void logWrongJaegerConfig() {
.map(TraceExportersSettings::getJaeger)
.filter((jaeger) -> !jaeger.getEnabled().isDisabled())
.ifPresent(settings -> {
if (StringUtils.hasText(settings.getUrl()) && !StringUtils.hasText(settings.getGrpc())) {
log.warn("In order to use Jaeger span exporter, please specify the grpc API endpoint property instead of the url.");
if (StringUtils.hasText(settings.getUrl()) && !StringUtils.hasText(settings.getEndpoint())) {
log.warn("In order to use Jaeger span exporter, please specify the grpc API 'endpoint' property instead of the 'url'.");
}
});
}

@Bean(destroyMethod = "shutdown")
@ConditionalOnProperty({"inspectit-eum-server.exporters.tracing.jaeger.enabled", "inspectit-eum-server.exporters.tracing.jaeger.grpc"})
@ConditionalOnExpression("(NOT new String('${inspectit-eum-server.exporters.tracing.jaeger.enabled}').toUpperCase().equals(T(rocks.inspectit.ocelot.config.model.exporters.ExporterEnabledState).DISABLED.toString())) AND (new String('${inspectit-eum-server.exporters.tracing.jaeger.grpc}').length() > 0)")
@ConditionalOnProperty({"inspectit-eum-server.exporters.tracing.jaeger.enabled", "inspectit-eum-server.exporters.tracing.jaeger.endpoint"})
@ConditionalOnExpression("(NOT new String('${inspectit-eum-server.exporters.tracing.jaeger.enabled}').toUpperCase().equals(T(rocks.inspectit.ocelot.config.model.exporters.ExporterEnabledState).DISABLED.toString())) AND (new String('${inspectit-eum-server.exporters.tracing.jaeger.endpoint}').length() > 0)")
public SpanExporter jaegerSpanExporter() {
JaegerExporterSettings jaegerExporterSettings = configuration.getExporters().getTracing().getJaeger();
@Valid JaegerExporterSettings jaegerExporterSettings = configuration.getExporters().getTracing().getJaeger();

ManagedChannel channel = ManagedChannelBuilder.forTarget(jaegerExporterSettings.getGrpc())
ManagedChannel channel = ManagedChannelBuilder.forTarget(jaegerExporterSettings.getEndpoint())
.usePlaintext()
.build();

log.info("Starting Jaeger Exporter on grpc '{}'", jaegerExporterSettings.getGrpc());
log.info("Starting Jaeger Exporter on grpc '{}'", jaegerExporterSettings.getEndpoint());
System.setProperty("otel.resource.attributes", "service.name=" + jaegerExporterSettings.getServiceName());

return JaegerGrpcSpanExporter.builder().setChannel(channel).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,14 @@ inspectit-eum-server:
# If jaeger exporter for the OT received spans is enabled.
enabled: IF_CONFIGURED

# The transport protocol
protocol: grpc

# Location of the jaeger gRPC API.
# Either a valid NameResolver-compliant URI, or an authority string.
# If this property is not set, the jaeger-exporter will not be started.
# grpc: localhost:14250
# endpoint: localhost:14250


# service name for all exported spans.
service-name: browser-js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import rocks.inspectit.ocelot.config.model.exporters.ExporterEnabledState;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -41,16 +42,14 @@ public class JaegerExporterIntTest {
public static final String SERVICE_NAME = "E2E-test";

@Container
public static GenericContainer<?> jaegerContainer = new GenericContainer<>("ghcr.io/open-telemetry/java-test-containers:jaeger")
.withExposedPorts(COLLECTOR_PORT, QUERY_PORT, HEALTH_PORT)
public static GenericContainer<?> jaegerContainer = new GenericContainer<>("ghcr.io/open-telemetry/java-test-containers:jaeger").withExposedPorts(COLLECTOR_PORT, QUERY_PORT, HEALTH_PORT)
.waitingFor(Wait.forHttp("/").forPort(HEALTH_PORT));

static class EnvInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
TestPropertyValues.of(String.format("inspectit-eum-server.exporters.tracing.jaeger.grpc=%s:%d", jaegerContainer
.getHost(), jaegerContainer.getMappedPort(COLLECTOR_PORT)), "inspectit-eum-server.exporters.tracing.jaeger.service-name=" + JaegerExporterIntTest.SERVICE_NAME)
TestPropertyValues.of("inspectit-eum-server.exporters.tracing.jaeger.enabled=" + ExporterEnabledState.ENABLED, String.format("inspectit-eum-server.exporters.tracing.jaeger.endpoint=%s:%d", jaegerContainer.getHost(), jaegerContainer.getMappedPort(COLLECTOR_PORT)), "inspectit-eum-server.exporters.tracing.jaeger.service-name=" + JaegerExporterIntTest.SERVICE_NAME, "inspectit-eum-server.exporters.tracing.jaeger.protocol=grpc")
.applyTo(applicationContext);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

/**
* This Test class tests whether the annotations on {@link TraceExportersConfiguration#jaegerSpanExporter()} are working as expected,
* i.e. whether the Bean only gets created when 'jaeger.enabled' is not set to DISABLED and 'jaeger.grpc' is not empty.
* i.e. whether the Bean only gets created when 'jaeger.enabled' is not set to DISABLED and 'jaeger.endpoint' is not empty.
*/
@SpringBootTest
class TraceExportersConfigurationTest {

@TestPropertySource(properties = {"inspectit-eum-server.exporters.tracing.jaeger.grpc=", "inspectit-eum-server.exporters.tracing.jaeger.enabled=ENABLED"})
@TestPropertySource(properties = {"inspectit-eum-server.exporters.tracing.jaeger.endpoint=", "inspectit-eum-server.exporters.tracing.jaeger.enabled=ENABLED"})
@Nested
public class MissingGrpcTest {
public class MissingEndpointTest {

@Autowired(required = false)
JaegerGrpcSpanExporter exporter;
Expand All @@ -29,7 +29,7 @@ public void testBeanWasNotCreated() {
}
}

@TestPropertySource(properties = {"inspectit-eum-server.exporters.tracing.jaeger.grpc=localhost:1234", "inspectit-eum-server.exporters.tracing.jaeger.enabled=DISABLED"})
@TestPropertySource(properties = {"inspectit-eum-server.exporters.tracing.jaeger.endpoint=localhost:1234", "inspectit-eum-server.exporters.tracing.jaeger.enabled=DISABLED", "inspectit-eum-server.exporters.tracing.jaeger.protocol=grpc"})
@Nested
public class DisabledTest {

Expand All @@ -42,7 +42,7 @@ public void testBeanWasNotCreated() {
}
}

@TestPropertySource(properties = {"inspectit-eum-server.exporters.tracing.jaeger.grpc=localhost:1234", "inspectit-eum-server.exporters.tracing.jaeger.enabled=ENABLED"})
@TestPropertySource(properties = {"inspectit-eum-server.exporters.tracing.jaeger.endpoint=localhost:1234", "inspectit-eum-server.exporters.tracing.jaeger.enabled=ENABLED", "inspectit-eum-server.exporters.tracing.jaeger.protocol=grpc"})
@Nested
public class BothAvailableTest {

Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ logbackVersion=1.2.10
# Ensure to adapt the netty version (inspectit-ocelot-core/build.gradle) when changing the OpenCensus version
openCensusVersion=0.28.3
# OpenTelemetry related
openTelemetryVersion=1.9.1
openTelemetryAlphaVersion=1.9.1-alpha
openTelemetryVersion=1.10.0
openTelemetryAlphaVersion=1.10.0-alpha

prometheusClientVersion=0.6.0
# appropriate netty version, see https://github.com/census-instrumentation/opencensus-java/blob/master/exporters/trace/ocagent/README.md
tcnativeVersion=2.0.20.Final
tcnativeVersion=2.0.20.Final
grpcVersion=1.43.1
9 changes: 8 additions & 1 deletion inspectit-ocelot-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ dependencies {
// for InMemorySpanExporter
platform("io.opentelemetry:opentelemetry-bom:${openTelemetryVersion}"),
"io.opentelemetry:opentelemetry-sdk-testing",
"io.opentelemetry:opentelemetry-exporter-logging",
platform("io.opentelemetry:opentelemetry-bom-alpha:${openTelemetryAlphaVersion}"),
"io.opentelemetry:opentelemetry-semconv",

Expand Down Expand Up @@ -243,7 +244,8 @@ task systemTest {
jvmArgs "-Dinspectit.config.file-based.path=$projectDir/src/system-test/resources/config"
// make inspectIT scan the workdir for configs
jvmArgs "-Dinspectit.publishOpenTelemetryToBootstrap=true" // make inspectIT push OTEL to the bootstrap
jvmArgs jacoco.asJvmArg + ",inclbootstrapclasses=true" // JaCoCo agent first + bootstrap instrumentation
jvmArgs jacoco.asJvmArg + ",inclbootstrapclasses=true"
// JaCoCo agent first + bootstrap instrumentation
jvmArgs "-javaagent:${agentJarPath}" // Our agent second.

// stricter checker makes sure that {@link Scope}s are closed on the correct thread and
Expand All @@ -257,6 +259,11 @@ task systemTest {
}

jacoco.enabled = false // Don't add the JaCoCo agent again.

// stricter checker makes sure that {@link Scope}s are closed on the correct thread and
// that they are not garbage collected before being closed.
jvmArgs "-Dio.opentelemetry.context.enableStrictContext=true"

}

doFirst { logger.lifecycle("Running system tests using ${javaExecutable}.") }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package rocks.inspectit.ocelot.agent;

import lombok.AllArgsConstructor;
import lombok.Value;
import rocks.inspectit.ocelot.bootstrap.AgentManager;
import rocks.inspectit.ocelot.bootstrap.Instances;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.logging.log4j.message.MessageFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import rocks.inspectit.ocelot.bootstrap.Instances;
import rocks.inspectit.ocelot.instrumentation.InstrumentationSysTestBase;
import rocks.inspectit.ocelot.logging.Log4J2LoggingRecorder;
import rocks.inspectit.ocelot.utils.TestUtils;
Expand All @@ -32,6 +33,8 @@ public static void initializeOpenTelemetry() {

@Test
public void logStringAndTraceExists() {
System.out.println(String.format("OTEL=%s, tracer=%s", Instances.openTelemetryController.getClass()
.getSimpleName(), Tracing.getTracer().getClass().getSimpleName()));
Log4J2LoggingRecorder.loggingEvents.clear();
String message = "This is a traced String in {}.";
String traceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ void destroyExporter() {
void assertTraceExported(Consumer<? super List<? extends SpanData>> assertions) {

await().atMost(15, TimeUnit.SECONDS).untilAsserted(() -> {
Map<String, List<SpanData>> traces = getExportedSpans().stream()
Map<String, List<io.opentelemetry.sdk.trace.data.SpanData>> traces = getExportedSpans().stream()
.collect(Collectors.groupingBy(s -> s.getSpanContext().getTraceId(), Collectors.toList()));
assertThat(traces.values()).anySatisfy(assertions);
assertThat(traces.values()).filteredOnAssertions(assertions).hasSize(1);
});
}

void assertSpansExported(Consumer<? super Collection<? extends SpanData>> assertions) {

void assertSpansExported(Consumer<? super Collection<? extends io.opentelemetry.sdk.trace.data.SpanData>> assertions) {
await().atMost(15, TimeUnit.SECONDS).untilAsserted(() -> {
assertions.accept(getExportedSpans());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.extension.trace.propagation.B3Propagator;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionTimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rocks.inspectit.ocelot.bootstrap.AgentManager;
import rocks.inspectit.ocelot.bootstrap.Instances;
import rocks.inspectit.ocelot.bootstrap.opentelemetry.NoopOpenTelemetryController;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -233,6 +232,17 @@ public static void waitForInstrumentationToComplete() {
});
}

/**
* Waits for the initialization of {@link rocks.inspectit.ocelot.core.opentelemetry.OpenTelemetryControllerImpl}, which is then registered to {@link Instances#openTelemetryController}
*/
public static void waitForOpenTelemetryControllerInitialization() {
Awaitility.await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
assertThat(NoopOpenTelemetryController.INSTANCE != Instances.openTelemetryController).isTrue();
assertThat(Instances.openTelemetryController.isEnabled()).isTrue();
assertThat(Instances.openTelemetryController.isConfigured()).isTrue();
});
}

public static Map<String, String> getCurrentTagsAsMap() {
Map<String, String> result = new HashMap<>();
InternalUtils.getTags(Tags.getTagger().getCurrentTagContext())
Expand Down Expand Up @@ -313,6 +323,13 @@ public static TimeSeries getTimeseries(String metricName, Map<String, String> ta
*/
public static InMemorySpanExporter initializeOpenTelemetryForSystemTesting() {

if (NoopOpenTelemetryController.INSTANCE != Instances.openTelemetryController) {
logger.info("shut down " + Instances.openTelemetryController.getClass().getSimpleName());

// shut down any previously configured OTELs
Instances.openTelemetryController.shutdown();
Instances.openTelemetryController = NoopOpenTelemetryController.INSTANCE;
}
// create an SdkTracerProvider with InMemorySpanExporter and LoggingSpanExporter
InMemorySpanExporter inMemSpanExporter = InMemorySpanExporter.create();

Expand Down Expand Up @@ -341,8 +358,7 @@ public static InMemorySpanExporter initializeOpenTelemetryForSystemTesting() {
modifiers.setInt(tracerField, tracerField.getModifiers() & ~Modifier.FINAL);
tracerField.set(null, tracer);

logger.info("OTEL_TRACER updated to {} ({})",
tracer, openTelemetry.getTracer("io.opentelemetry.opencensusshim"));
logger.info("OTEL_TRACER updated to {} ({})", tracer, openTelemetry.getTracer("io.opentelemetry.opencensusshim"));
} catch (Exception e) {
logger.error("Failed to set OTEL_TRACER in OpenTelemetrySpanBuilderImpl", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import rocks.inspectit.ocelot.bootstrap.instrumentation.IHookManager;
import rocks.inspectit.ocelot.bootstrap.instrumentation.noop.NoopHookManager;
import rocks.inspectit.ocelot.bootstrap.instrumentation.noop.NoopObjectAttachments;
import rocks.inspectit.ocelot.bootstrap.opentelemetry.IOpenTelemetryController;
import rocks.inspectit.ocelot.bootstrap.opentelemetry.NoopOpenTelemetryController;

import java.net.URL;

Expand Down Expand Up @@ -41,4 +43,6 @@ public class Instances {
public static LogTraceCorrelator logTraceCorrelator = NoopLogTraceCorrelator.INSTANCE;

public static TraceIdInjector traceIdInjector = NoopTraceIdInjector.INSTANCE;

public static IOpenTelemetryController openTelemetryController = NoopOpenTelemetryController.INSTANCE;
}
Loading