Skip to content

Commit bfc722a

Browse files
committed
Add documentation for using the extension without agent
1 parent e140374 commit bfc722a

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

gcp-auth-extension/README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Here is a list of configurable options for the extension:
4040

4141
## Usage
4242

43+
### With OpenTelemetry Java agent
44+
4345
The OpenTelemetry Java Agent Extension can be easily added to any Java application by modifying the startup command to the application.
4446
For more information on Extensions, see the [documentation here](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/examples/extension/README.md).
4547

@@ -53,8 +55,7 @@ def extensionPath = <Google Cloud Authentication Extension location>
5355
def googleCloudProjectId = <Your Google Cloud Project ID>
5456
def googleOtlpEndpoint = <Google Cloud OTLP endpoint>
5557
56-
application {
57-
...
58+
val autoconf_config = listOf(
5859
"-javaagent:${otelAgentPath}",
5960
"-Dotel.javaagent.extensions=${extensionPath}",
6061
// Configure the GCP Auth extension using system properties.
@@ -66,7 +67,52 @@ application {
6667
// Optionally enable the built-in GCP resource detector
6768
'-Dotel.resource.providers.gcp.enabled=true'
6869
'-Dotel.traces.exporter=otlp',
69-
'-Dotel.metrics.exporter=logging',
70+
'-Dotel.metrics.exporter=logging'
71+
)
72+
73+
application {
74+
...
75+
applicationDefaultJvmArgs = autoconf_config
76+
...
77+
}
78+
```
79+
80+
### Without OpenTelemetry Java agent
81+
82+
This extension can be used without the OpenTelemetry Java agent by leveraging the [OpenTelemetry SDK Autoconfigure](https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md) module.\
83+
When using the autoconfigured SDK, simply adding this extension as a dependency automatically configures authentication headers and resource attributes for spans, enabling export to Google Cloud.
84+
85+
Below is a snippet showing how to use this extension as a dependency when the application is not instrumented using the OpenTelemetry Java agent.
86+
87+
```gradle
88+
dependencies {
89+
implementation("io.opentelemetry:opentelemetry-api")
90+
implementation("io.opentelemetry:opentelemetry-sdk")
91+
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
92+
implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
93+
// use the shaded variant of the dependency
94+
implementation("io.opentelemetry.contrib:opentelemetry-gcp-auth-extension:<VERSION>:shaded")
95+
96+
// other dependencies
97+
...
98+
99+
}
100+
101+
val autoconf_config = listOf(
102+
'-Dgoogle.cloud.project=your-gcp-project-id',
103+
'-Dotel.exporter.otlp.endpoint=https://your.otlp.endpoint:1234',
104+
'-Dotel.traces.exporter=otlp',
105+
'-Dotel.java.global-autoconfigure.enabled=true'
106+
107+
// any additional args
108+
...
109+
)
110+
111+
application {
112+
applicationDefaultJvmArgs = autoconf_config
113+
114+
// additional configuration
115+
...
70116
}
71117
```
72118

gcp-auth-extension/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ val agent: Configuration by configurations.creating {
1515

1616
dependencies {
1717
annotationProcessor("com.google.auto.service:auto-service")
18-
compileOnly("com.google.auto.service:auto-service-annotations")
19-
2018
// We use `compileOnly` dependency because during runtime all necessary classes are provided by
2119
// javaagent itself.
20+
compileOnly("com.google.auto.service:auto-service-annotations")
2221
compileOnly("io.opentelemetry:opentelemetry-api")
2322
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
2423
compileOnly("io.opentelemetry:opentelemetry-exporter-otlp")

0 commit comments

Comments
 (0)