Skip to content

Commit

Permalink
Fix the sample code shown in README
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 committed Sep 20, 2024
1 parent 10d8c86 commit 3f1bd36
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
10 changes: 5 additions & 5 deletions exporters/auto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ To leverage the GCP extensions to this, simply add the exporter-auto dependency
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-auto</artifactId>
<version>0.27.0-alpha</version>
<version>0.31.0-alpha</version>
<!-- Add the classifier if you explicitly wish to use the shaded variant -->
<classifier>shaded</classifier>
</dependency>
```

#### Gradle
```groovy
implementation "com.google.cloud.opentelemetry:exporter-auto:0.27.0-alpha"
implementation "com.google.cloud.opentelemetry:exporter-auto:0.31.0-alpha"
```

To use the shaded variant with Gradle,
```groovy
implementation "com.google.cloud.opentelemetry:exporter-auto:0.27.0-alpha:shaded"
implementation "com.google.cloud.opentelemetry:exporter-auto:0.31.0-alpha:shaded"
```

#### Shaded Local JAR
Expand All @@ -38,9 +38,9 @@ You can download the shaded JAR for `exporter-auto` from the following link -
https://repo1.maven.org/maven2/com/google/cloud/opentelemetry/exporter-auto/<VERSION>-alpha/exporter-auto-<VERSION>-alpha-shaded.jar
```
Replace `<VERSION>` with the version you wish to download. For instance, shaded
variant for `v0.27.0`, will be found at -
variant for `v0.31.0`, will be found at -

`https://repo1.maven.org/maven2/com/google/cloud/opentelemetry/exporter-auto/0.27.0-alpha/exporter-auto-0.27.0-alpha-shaded.jar`
`https://repo1.maven.org/maven2/com/google/cloud/opentelemetry/exporter-auto/0.31.0-alpha/exporter-auto-0.31.0-alpha-shaded.jar`

**Note: Make sure to use the latest release [![LatestRelease][maven-image]][maven-url].**

Expand Down
25 changes: 18 additions & 7 deletions exporters/trace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,39 @@ config:
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-trace</artifactId>
<version>0.20.0</version>
<version>0.31.0</version>
</dependency>
```

### Usage
If you are running in a GCP environment, the exporter will automatically authenticate using the environment's service account. If not, you will need to follow the instructions in Authentication.
If you are running in a GCP environment, the exporter will automatically authenticate using the environment's service account. If not, you will need to follow the instructions in Authentication.

See [the code example](../../examples/trace) for details.

#### Create the exporter

You can create exporter and register it in the OpenTelemetry SDK using the default configuration as follows:
You can create exporter using the default configuration as follows:

```java
TraceExporter traceExporter = TraceExporter.createWithDefaultConfiguration();
OpenTelemetrySdk.getTracerProvider().addSpanProcessor(SimpleSpanProcessor.newBuilder(traceExporter).build());
SpanExporter traceExporter = TraceExporter.createWithDefaultConfiguration();
```

You can also customize the configuration using a TraceConfiguration object
```java
TraceExporter traceExporter = TraceExporter.createWithConfiguration(
SpanExporter traceExporter = TraceExporter.createWithConfiguration(
TraceConfiguration.builder().setProjectId("myCoolGcpProject").build()
);
OpenTelemetrySdk.getTracerProvider().addSpanProcessor(SimpleSpanProcessor.newBuilder(traceExporter).build());
```

You can register a `SpanExporter` with your OpenTelemetry instance as follows:

```java
OpenTelemetrySdk.builder()
.setTracerProvider(
SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(traceExporter).build())
.build())
.build();
```

#### Specifying a project ID
Expand Down

0 comments on commit 3f1bd36

Please sign in to comment.