-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to latest otel and reduce fork
- Loading branch information
Showing
67 changed files
with
2,803 additions
and
1,072 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
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
43 changes: 43 additions & 0 deletions
43
.../src/main/java/com/microsoft/applicationinsights/agent/bootstrap/AiLazyConfiguration.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,43 @@ | ||
/* | ||
* ApplicationInsights-Java | ||
* Copyright (c) Microsoft Corporation | ||
* All rights reserved. | ||
* | ||
* MIT License | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
* software and associated documentation files (the ""Software""), to deal in the Software | ||
* without restriction, including without limitation the rights to use, copy, modify, merge, | ||
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
* persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.microsoft.applicationinsights.agent.bootstrap; | ||
|
||
public class AiLazyConfiguration { | ||
|
||
private static volatile Accessor accessor; | ||
|
||
public static void setAccessor(Accessor accessor) { | ||
AiLazyConfiguration.accessor = accessor; | ||
} | ||
|
||
public static void lazyLoad() { | ||
if (accessor != null) { | ||
accessor.lazyLoad(); | ||
} | ||
} | ||
|
||
public interface Accessor { | ||
void lazyLoad(); | ||
} | ||
|
||
private AiLazyConfiguration() {} | ||
} |
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,89 @@ | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
|
||
plugins { | ||
id("ai.java-conventions") | ||
id("ai.shadow-conventions") | ||
} | ||
|
||
// this configuration collects libs that will be placed in the bootstrap classloader | ||
val bootstrapLibs: Configuration by configurations.creating { | ||
isCanBeResolved = true | ||
isCanBeConsumed = false | ||
} | ||
// this configuration collects libs that will be placed in the agent classloader, isolated from the instrumented application code | ||
val javaagentLibs: Configuration by configurations.creating { | ||
isCanBeResolved = true | ||
isCanBeConsumed = false | ||
} | ||
// this configuration stores the upstream agent dep that's extended by this project | ||
val upstreamAgent: Configuration by configurations.creating { | ||
isCanBeResolved = true | ||
isCanBeConsumed = false | ||
} | ||
|
||
dependencies { | ||
// include everything from otel agent for testing | ||
upstreamAgent("io.opentelemetry.javaagent:opentelemetry-agent-for-testing") | ||
} | ||
|
||
tasks { | ||
jar { | ||
enabled = false | ||
} | ||
|
||
// building the final javaagent jar is done in 3 steps: | ||
|
||
// 1. all distro-specific javaagent libs are relocated (by the ai.shadow-conventions plugin) | ||
val relocateJavaagentLibs by registering(ShadowJar::class) { | ||
configurations = listOf(javaagentLibs) | ||
|
||
archiveFileName.set("javaagentLibs-relocated.jar") | ||
} | ||
|
||
// 2. the distro javaagent libs are then isolated - moved to the inst/ directory | ||
// having a separate task for isolating javaagent libs is required to avoid duplicates with the upstream javaagent | ||
// duplicatesStrategy in shadowJar won't be applied when adding files with with(CopySpec) because each CopySpec has | ||
// its own duplicatesStrategy | ||
val isolateJavaagentLibs by registering(Copy::class) { | ||
dependsOn(relocateJavaagentLibs) | ||
isolateClasses(relocateJavaagentLibs.get().outputs.files) | ||
|
||
into("$buildDir/isolated/javaagentLibs") | ||
} | ||
|
||
// 3. the relocated and isolated javaagent libs are merged together with the bootstrap libs (which undergo relocation | ||
// in this task) and the upstream javaagent jar; duplicates are removed | ||
shadowJar { | ||
configurations = listOf(bootstrapLibs, upstreamAgent) | ||
|
||
dependsOn(isolateJavaagentLibs) | ||
from(isolateJavaagentLibs.get().outputs) | ||
|
||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE | ||
|
||
manifest { | ||
attributes( | ||
mapOf( | ||
"Main-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent", | ||
"Agent-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent", | ||
"Premain-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent", | ||
"Can-Redefine-Classes" to true, | ||
"Can-Retransform-Classes" to true | ||
) | ||
) | ||
} | ||
} | ||
|
||
assemble { | ||
dependsOn(shadowJar) | ||
} | ||
} | ||
|
||
fun CopySpec.isolateClasses(jars: Iterable<File>) { | ||
jars.forEach { | ||
from(zipTree(it)) { | ||
into("inst") | ||
rename("^(.*)\\.class\$", "\$1.classdata") | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
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
Oops, something went wrong.