Skip to content

Commit 999122f

Browse files
committed
Add GCP auth extension module to contrib repo
1 parent 6d3a142 commit 999122f

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

gcp-auth-extension/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Google Cloud Authentication Extension for OpenTelemetry Java Agent
2+
3+
The Google Cloud Auth Extension allows the users to export telemetry from their applications auto-instrumented using the OpenTelemetry Java Agent to Google Cloud using the built-in OTLP exporters.
4+
The extension takes care of the necessary configuration required to authenticate to GCP to successfully export telemetry.
5+
6+
## Prerequisites
7+
8+
### Ensure the presence of Google Cloud Credentials on your machine/environment
9+
10+
```shell
11+
gcloud auth application-default login
12+
```
13+
Executing this command will save your application credentials to default path which will depend on the type of machine -
14+
- Linux, macOS: `$HOME/.config/gcloud/application_default_credentials.json`
15+
- Windows: `%APPDATA%\gcloud\application_default_credentials.json`
16+
17+
**NOTE: This method of authentication is not recommended for production environments.**
18+
19+
Next, export the credentials to `GOOGLE_APPLICATION_CREDENTIALS` environment variable -
20+
21+
For Linux & MacOS:
22+
```shell
23+
export GOOGLE_APPLICATION_CREDENTIALS=$HOME/.config/gcloud/application_default_credentials.json
24+
```
25+
26+
These credentials are built-in running in a Google App Engine, Google Cloud Shell or Google Compute Engine environment.
27+
28+
### Configuring the extension
29+
30+
The extension can be configured either by environment variables or system properties.
31+
32+
Here is a list of configurable options for the extension:
33+
34+
- `GOOGLE_CLOUD_PROJECT`: Environment variable that represents the Google Cloud Project ID to which the telemetry needs to be exported.
35+
- Can also be configured using `google.cloud.project` system property.
36+
- If this option is not configured, the extension would infer GCP Project ID from the application default credentials. For more information on application default credentials, see [here](https://cloud.google.com/docs/authentication/application-default-credentials).
37+
38+
## Usage
39+
40+
The OpenTelemetry Java Agent Extension can be easily added to any Java application by modifying the startup command to the application.
41+
For more information on Extensions, see the [documentation here](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/examples/extension/README.md).
42+
43+
Below is a snippet showing how to add the extension to a Java application using the Gradle build system.
44+
45+
```gradle
46+
// Specify OpenTelemetry Autoinstrumentation Java Agent Path.
47+
def otelAgentPath = <OpenTelemetry Java Agent location>
48+
// Specify the path for Google Cloud Authentication Extension for the Java Agent.
49+
def extensionPath = <Google Cloud Authentication Extension location>
50+
def googleCloudProjectId = <Your Google Cloud Project ID>
51+
def googleOtlpEndpoint = <Google Cloud OTLP endpoint>
52+
53+
application {
54+
...
55+
"-javaagent:${otelAgentPath}",
56+
"-Dotel.javaagent.extensions=${extensionPath}",
57+
// Configure the GCP Auth extension using system properties.
58+
// This can also be configured using environment variables.
59+
"-Dgoogle.cloud.project=${googleCloudProjectId}",
60+
// Configure auto instrumentation.
61+
"-Dotel.exporter.otlp.traces.endpoint=${googleOtlpEndpoint}",
62+
'-Dotel.java.global-autoconfigure.enabled=true',
63+
// Optionally enable the built-in GCP resource detector
64+
'-Dotel.resource.providers.gcp.enabled=true'
65+
'-Dotel.traces.exporter=otlp',
66+
'-Dotel.metrics.exporter=logging',
67+
}
68+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
plugins {
2+
id("otel.java-conventions")
3+
4+
id("otel.publish-conventions")
5+
}
6+
7+
description = "OpenTelemetry Java Agent Extension that enables authentication support for OTLP exporters"
8+
otelJava.moduleName.set("io.opentelemetry.contrib.gcp.auth")
9+
10+
dependencies {
11+
testImplementation("org.junit.jupiter:junit-jupiter")
12+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
13+
}
14+
15+
tasks.test {
16+
useJUnitPlatform()
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# TODO: uncomment when ready to mark as stable
2+
# otel.stable=true
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.gcp.auth;
7+
8+
public final class Main {
9+
public void foo() {
10+
// TODO: Implement this
11+
}
12+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ include(":gcp-resources")
6262
include(":span-stacktrace")
6363
include(":inferred-spans")
6464
include(":opamp-client")
65+
include(":gcp-auth-extension")

0 commit comments

Comments
 (0)