-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PoC for setting app server middleware attributes from splunk distro. * First iteration of jetty test matrix. * Proper end-to-end test for Jetty. * Added copyright headers. * Spotless. * Temporarily build test images before smoke test. * Rename shared to bootstrap and other PR fixes. * Removed middleware submodule. * Verify middleware attributes also in webapp test. * spotless * Add middleware attributes to the server span only. * Add a TODO reference to an important PR.
- Loading branch information
Showing
24 changed files
with
948 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
plugins { | ||
id("com.github.johnrengelman.shadow") version "6.0.0" | ||
} | ||
configurations { | ||
customShadow | ||
} | ||
dependencies { | ||
customShadow project(path: ":custom", configuration: "shadow") | ||
customShadow project(path: ":instrumentation", configuration: "shadow") | ||
implementation "io.opentelemetry.javaagent:opentelemetry-javaagent:${versions.opentelemetryJavaagent}:all" | ||
implementation project(":bootstrap") | ||
} | ||
|
||
archivesBaseName = "splunk-otel-javaagent" | ||
|
||
compileJava { | ||
options.release.set(8) | ||
} | ||
|
||
CopySpec isolateSpec() { | ||
return copySpec { | ||
configurations.customShadow.files.each { | ||
from(zipTree(it)) { | ||
into("inst") | ||
rename("(^.*)\\.class\$", "\$1.classdata") | ||
} | ||
} | ||
} | ||
} | ||
|
||
tasks { | ||
shadowJar { | ||
dependsOn ':custom:shadowJar' | ||
dependsOn ':instrumentation:shadowJar' | ||
dependsOn ':bootstrap:jar' | ||
with isolateSpec() | ||
|
||
/// TODO - with this set to EXCLUDE, service files will not be merged between instrumentation and custom | ||
duplicatesStrategy = DuplicatesStrategy.INCLUDE | ||
|
||
mergeServiceFiles { | ||
include("inst/META-INF/services/*") | ||
} | ||
exclude("**/module-info.class") | ||
|
||
// Prevents conflict with other SLF4J instances. Important for premain. | ||
relocate("org.slf4j", "io.opentelemetry.javaagent.slf4j") | ||
// rewrite dependencies calling Logger.getLogger | ||
relocate("java.util.logging.Logger", "io.opentelemetry.javaagent.bootstrap.PatchLogger") | ||
|
||
// prevents conflict with library instrumentation | ||
relocate("io.opentelemetry.instrumentation.api", "io.opentelemetry.javaagent.shaded.instrumentation.api") | ||
|
||
// relocate OpenTelemetry API | ||
relocate("io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api") | ||
relocate("io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context") | ||
|
||
manifest { | ||
attributes.put("Main-Class", "io.opentelemetry.javaagent.OpenTelemetryAgent") | ||
attributes.put("Agent-Class", "com.splunk.opentelemetry.SplunkAgent") | ||
attributes.put("Premain-Class", "com.splunk.opentelemetry.SplunkAgent") | ||
attributes.put("Can-Redefine-Classes", "true") | ||
attributes.put("Can-Retransform-Classes", "true") | ||
attributes.put("Implementation-Vendor", "Splunk") | ||
attributes.put("Implementation-Version", "splunk-${project.version}-otel-${versions["opentelemetryJavaagent"]}") | ||
} | ||
} | ||
|
||
assemble { | ||
dependsOn(shadowJar) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plugins { | ||
id "java" | ||
} | ||
|
||
compileJava { | ||
options.release.set(8) | ||
} | ||
|
||
dependencies { | ||
implementation "org.slf4j:slf4j-api:1.7.30" | ||
} |
42 changes: 42 additions & 0 deletions
42
bootstrap/src/main/java/com/splunk/opentelemetry/javaagent/bootstrap/MiddlewareHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.opentelemetry.javaagent.bootstrap; | ||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class MiddlewareHolder { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(MiddlewareHolder.class); | ||
|
||
public static final AtomicReference<String> middlewareName = new AtomicReference<>(); | ||
public static final AtomicReference<String> middlewareVersion = new AtomicReference<>(); | ||
|
||
public static void trySetName(String name) { | ||
if (!middlewareName.compareAndSet(null, name)) { | ||
log.debug("Trying to re-set middleware name from {} to {}", middlewareName.get(), name); | ||
} | ||
} | ||
|
||
public static void trySetVersion(String version) { | ||
if (!middlewareVersion.compareAndSet(null, version)) { | ||
log.debug( | ||
"Trying to re-set middleware version from {} to {}", middlewareVersion.get(), version); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...m/src/main/java/com/splunk/opentelemetry/middleware/MiddlewareAttributeSpanProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.opentelemetry.middleware; | ||
|
||
import com.splunk.opentelemetry.javaagent.bootstrap.MiddlewareHolder; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.common.CompletableResultCode; | ||
import io.opentelemetry.sdk.trace.ReadWriteSpan; | ||
import io.opentelemetry.sdk.trace.ReadableSpan; | ||
import io.opentelemetry.sdk.trace.SpanProcessor; | ||
|
||
public class MiddlewareAttributeSpanProcessor implements SpanProcessor { | ||
|
||
@Override | ||
public void onStart(Context parentContext, ReadWriteSpan span) { | ||
String middlewareName = MiddlewareHolder.middlewareName.get(); | ||
String middlewareVersion = MiddlewareHolder.middlewareVersion.get(); | ||
// Getting span kind is not the most straightforward or cheap operation apparently. | ||
// TODO: Once this PR is merged and released, use span.getKind directly: | ||
// https://github.com/open-telemetry/opentelemetry-java/pull/2162 | ||
// Let's do quick cheap null checks first and exit quickly. | ||
if ((middlewareName == null && middlewareVersion == null) | ||
|| span.toSpanData().getKind() != Span.Kind.SERVER) { | ||
return; | ||
} | ||
if (middlewareName != null) { | ||
span.setAttribute(MiddlewareAttributes.MIDDLEWARE_NAME.key, middlewareName); | ||
} | ||
if (middlewareVersion != null) { | ||
span.setAttribute(MiddlewareAttributes.MIDDLEWARE_VERSION.key, middlewareVersion); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isStartRequired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onEnd(ReadableSpan span) {} | ||
|
||
@Override | ||
public boolean isEndRequired() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public CompletableResultCode shutdown() { | ||
return CompletableResultCode.ofSuccess(); | ||
} | ||
|
||
@Override | ||
public CompletableResultCode forceFlush() { | ||
return CompletableResultCode.ofSuccess(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
custom/src/main/java/com/splunk/opentelemetry/middleware/MiddlewareAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.opentelemetry.middleware; | ||
|
||
public enum MiddlewareAttributes { | ||
MIDDLEWARE_NAME("middleware.name"), | ||
MIDDLEWARE_VERSION("middleware.version"); | ||
|
||
public final String key; | ||
|
||
MiddlewareAttributes(String key) { | ||
this.key = key; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/com/splunk/opentelemetry/middleware/MiddlewareBootstrapPackagesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.opentelemetry.middleware; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.splunk.opentelemetry.javaagent.bootstrap.MiddlewareHolder; | ||
import io.opentelemetry.javaagent.spi.BootstrapPackagesProvider; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@AutoService(BootstrapPackagesProvider.class) | ||
public class MiddlewareBootstrapPackagesProvider implements BootstrapPackagesProvider { | ||
|
||
@Override | ||
public List<String> getPackagePrefixes() { | ||
return Collections.singletonList(MiddlewareHolder.class.getPackage().getName()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
custom/src/main/java/com/splunk/opentelemetry/middleware/MiddlewareTracerCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.opentelemetry.middleware; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.opentelemetry.javaagent.spi.TracerCustomizer; | ||
import io.opentelemetry.sdk.trace.TracerSdkManagement; | ||
|
||
@AutoService(TracerCustomizer.class) | ||
public class MiddlewareTracerCustomizer implements TracerCustomizer { | ||
|
||
@Override | ||
public void configure(TracerSdkManagement tracerManagement) { | ||
tracerManagement.addSpanProcessor(new MiddlewareAttributeSpanProcessor()); | ||
} | ||
} |
Oops, something went wrong.