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

Add elastic specific env variables for withOtelEnv #1250

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")