Total Lines | 30 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package tracerexporters |
||
2 | |||
3 | import ( |
||
4 | "os" |
||
5 | |||
6 | texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace" |
||
7 | sdktrace "go.opentelemetry.io/otel/sdk/trace" |
||
8 | ) |
||
9 | |||
10 | // NewGCP creates a new Google Cloud tracer with optional headers for credentials and project ID. |
||
11 | func NewGCP(headers map[string]string) (sdktrace.SpanExporter, error) { |
||
12 | |||
13 | if credentials, exists := headers["google-application-credentials"]; exists && credentials != "" { |
||
14 | os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credentials) |
||
15 | } |
||
16 | |||
17 | if projectID, exists := headers["google-cloud-project"]; exists && projectID != "" { |
||
18 | exporter, err := texporter.New(texporter.WithProjectID(projectID)) |
||
19 | if err != nil { |
||
20 | return nil, err |
||
21 | } |
||
22 | return exporter, nil |
||
23 | } |
||
24 | |||
25 | exporter, err := texporter.New() |
||
26 | if err != nil { |
||
27 | return nil, err |
||
28 | } |
||
29 | |||
30 | return exporter, nil |
||
31 | } |
||
32 |