Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Add elastic specific env variables for withOtelEnv (#1250)
Browse files Browse the repository at this point in the history
* Add elastic specific env variables for withOtelEnv

* Add service name env variable
  • Loading branch information
v1v authored Aug 25, 2021
1 parent 2d68d2f commit 05004c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions vars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3158,6 +3158,9 @@ environment variables:
* `OTEL_EXPORTER_OTLP_ENDPOINT`
* `OTEL_SERVICE_NAME`
* `OTEL_EXPORTER_OTLP_HEADERS`
* `ELASTIC_APM_SECRET_TOKEN`
* `ELASTIC_APM_SERVER_URL`
* `ELASTIC_APM_SERVICE_NAME`

```
withOtelEnv() {
Expand All @@ -3172,6 +3175,8 @@ environment variables:

* credentialsId: the name of the credentials. Optional.

**NOTE**: It requires the [OpenTelemetry plugin](https://plugins.jenkins.io/opentelemetry")

## withSecretVault
Grab a secret from the vault, define the environment variables which have been
passed as parameters and mask the secrets
Expand Down
9 changes: 7 additions & 2 deletions vars/withOtelEnv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ def call(Map args = [:], Closure body) {

// Then, mask and provide the environment variables.
withCredentials([string(credentialsId: credentialsId, variable: 'OTEL_TOKEN_ID')]) {
def entrypoint = otelPlugin.getEndpoint()
def serviceName = otelPlugin.getServiceName()
withEnvMask(vars: [
[var: 'OTEL_EXPORTER_OTLP_ENDPOINT', password: otelPlugin.getEndpoint()],
[var: 'OTEL_SERVICE_NAME', password: otelPlugin.getServiceName()],
[var: 'ELASTIC_APM_SECRET_TOKEN', password: env.OTEL_TOKEN_ID],
[var: 'ELASTIC_APM_SERVER_URL', password: entrypoint],
[var: 'ELASTIC_APM_SERVICE_NAME', password: serviceName],
[var: 'OTEL_EXPORTER_OTLP_ENDPOINT', password: entrypoint],
[var: 'OTEL_SERVICE_NAME', password: serviceName],
[var: 'OTEL_EXPORTER_OTLP_HEADERS', password: "authorization=Bearer ${env.OTEL_TOKEN_ID}"]
]) {
body()
Expand Down
5 changes: 5 additions & 0 deletions vars/withOtelEnv.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ environment variables:
* `OTEL_EXPORTER_OTLP_ENDPOINT`
* `OTEL_SERVICE_NAME`
* `OTEL_EXPORTER_OTLP_HEADERS`
* `ELASTIC_APM_SECRET_TOKEN`
* `ELASTIC_APM_SERVER_URL`
* `ELASTIC_APM_SERVICE_NAME`

```
withOtelEnv() {
Expand All @@ -17,3 +20,5 @@ environment variables:
```

* credentialsId: the name of the credentials. Optional.

**NOTE**: It requires the [OpenTelemetry plugin](https://plugins.jenkins.io/opentelemetry")

0 comments on commit 05004c6

Please sign in to comment.