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

Set OTEL_EXPORTER_OTLP_HEADERS #1234

Merged
merged 2 commits into from
Aug 24, 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
16 changes: 16 additions & 0 deletions src/test/groovy/WithOtelEnvStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ class WithOtelEnvStepTests extends ApmBasePipelineTest {
assertTrue(assertMethodCallContainsPattern('error', 'withOtelEnv: opentelemetry plugin is not available'))
assertJobStatusFailure()
}

@Test
void test_env_variable_defined() throws Exception {
addEnvVar('OTEL_EXPORTER_OTLP_HEADERS', 'foo')
try {
script.call(){
//NOOP
}
} catch(e){
//NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', 'withOtelEnv: OTEL_EXPORTER_OTLP_HEADERS env variable is already defined'))
assertJobStatusFailure()
}

}
2 changes: 1 addition & 1 deletion vars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3141,7 +3141,7 @@ environment variables:

* `OTEL_EXPORTER_OTLP_ENDPOINT`
* `OTEL_SERVICE_NAME`
* `OTEL_TOKEN_ID`
* `OTEL_EXPORTER_OTLP_HEADERS`

```
withOtelEnv() {
Expand Down
17 changes: 11 additions & 6 deletions vars/withOtelEnv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def call(Map args = [:], Closure body) {
error('withOtelEnv: opentelemetry plugin is not available')
}

if (env.OTEL_EXPORTER_OTLP_HEADERS?.trim()) {
error('withOtelEnv: OTEL_EXPORTER_OTLP_HEADERS env variable is already defined.')
}

def otelPlugin = getOtelPlugin()

// In case the credentialsId argument was not passed, then let's use the
Expand All @@ -44,12 +48,13 @@ def call(Map args = [:], Closure body) {
}
}

// Then, mask and provide the environemnt variables.
withEnvMask(vars: [
[var: "OTEL_EXPORTER_OTLP_ENDPOINT", password: otelPlugin.getEndpoint()],
[var: "OTEL_SERVICE_NAME", password: otelPlugin.getServiceName()],
]) {
withCredentials([string(credentialsId: credentialsId, variable: 'OTEL_TOKEN_ID')]) {
// Then, mask and provide the environment variables.
withCredentials([string(credentialsId: credentialsId, variable: 'OTEL_TOKEN_ID')]) {
withEnvMask(vars: [
[var: 'OTEL_EXPORTER_OTLP_ENDPOINT', password: otelPlugin.getEndpoint()],
[var: 'OTEL_SERVICE_NAME', password: otelPlugin.getServiceName()],
[var: 'OTEL_EXPORTER_OTLP_HEADERS', password: "authorization=Bearer ${env.OTEL_TOKEN_ID}"]
]) {
body()
}
}
Expand Down
2 changes: 1 addition & 1 deletion vars/withOtelEnv.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ environment variables:

* `OTEL_EXPORTER_OTLP_ENDPOINT`
* `OTEL_SERVICE_NAME`
* `OTEL_TOKEN_ID`
* `OTEL_EXPORTER_OTLP_HEADERS`

```
withOtelEnv() {
Expand Down