Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 05f5589

Browse files
author
Steven Karis
authored
Exporter/opencensus: add option for custom headers (#392)
Allow creating an OpenCensus exporter with custom headers following suit with: [census-ecosystem/opencensus-go-exporter-ocagent#43](census-ecosystem/opencensus-go-exporter-ocagent#43)
1 parent ee33463 commit 05f5589

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ please see the [exporter README.md](exporter/exporterparser/README.md).
152152
```yaml
153153
exporters:
154154
opencensus:
155+
headers: {"X-test-header": "test-header"}
156+
compression: "gzip"
155157
endpoint: "127.0.0.1:55678"
156158

157159
jaeger:

exporter/exporterparser/opencensus.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import (
3030
)
3131

3232
type opencensusConfig struct {
33-
Endpoint string `mapstructure:"endpoint,omitempty"`
34-
Compression string `mapstructure:"compression,omitempty"`
33+
Endpoint string `mapstructure:"endpoint,omitempty"`
34+
Compression string `mapstructure:"compression,omitempty"`
35+
Headers map[string]string `mapstructure:"headers,omitempty"`
3536
// TODO: add insecure, service name options.
3637
}
3738

@@ -67,6 +68,9 @@ func OpenCensusTraceExportersFromViper(v *viper.Viper) (tes []exporter.TraceExpo
6768
return nil, nil, nil, fmt.Errorf("Unsupported compression type: %s", ocac.Compression)
6869
}
6970
}
71+
if len(ocac.Headers) > 0 {
72+
opts = append(opts, ocagent.WithHeaders(ocac.Headers))
73+
}
7074

7175
sde, serr := ocagent.NewExporter(opts...)
7276
if serr != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/census-instrumentation/opencensus-service
22

33
require (
44
cloud.google.com/go v0.32.0 // indirect
5-
contrib.go.opencensus.io/exporter/ocagent v0.4.3
5+
contrib.go.opencensus.io/exporter/ocagent v0.4.4
66
contrib.go.opencensus.io/exporter/stackdriver v0.9.1
77
git.apache.org/thrift.git v0.0.0-20181101003639-92be4f312b88 // indirect
88
github.com/Azure/azure-sdk-for-go v6.0.0-beta+incompatible // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ cloud.google.com/go v0.32.0 h1:DSt59WoyNcfAInilEpfvm2ugq8zvNyaHAm9MkzOwRQ4=
66
cloud.google.com/go v0.32.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
77
contrib.go.opencensus.io/exporter/ocagent v0.4.3 h1:QjNm697iO7CZ09IxxSiCUzOhALENIsLsixdPwjV1yGs=
88
contrib.go.opencensus.io/exporter/ocagent v0.4.3/go.mod h1:YuG83h+XWwqWjvCqn7vK4KSyLKhThY3+gNGQ37iS2V0=
9+
contrib.go.opencensus.io/exporter/ocagent v0.4.4 h1:6v7OlUmiBDhvbYcHPWp8LHO8wh9jJY8f4mO34J4GJiA=
10+
contrib.go.opencensus.io/exporter/ocagent v0.4.4/go.mod h1:YuG83h+XWwqWjvCqn7vK4KSyLKhThY3+gNGQ37iS2V0=
911
contrib.go.opencensus.io/exporter/stackdriver v0.9.1 h1:W6APgQ9we4BH8U8bnq/FvwLKo2WSMHuiMkkS/Slkg30=
1012
contrib.go.opencensus.io/exporter/stackdriver v0.9.1/go.mod h1:hNe5qQofPbg6bLQY5wHCvQ7o+2E5P8PkegEuQ+MyRw0=
1113
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999 h1:sihTnRgTOUSCQz0iS0pjZuFQy/z7GXCJgSBg3+rZKHw=

0 commit comments

Comments
 (0)