Total Lines | 30 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package meterexporters |
||
2 | |||
3 | import ( |
||
4 | "os" |
||
5 | |||
6 | mexporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric" |
||
7 | "go.opentelemetry.io/otel/sdk/metric" |
||
8 | ) |
||
9 | |||
10 | // NewGCP creates a new Google Cloud metric exporter with optional headers for credentials and project ID. |
||
11 | func NewGCP(headers map[string]string) (metric.Exporter, 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 := mexporter.New(mexporter.WithProjectID(projectID)) |
||
19 | if err != nil { |
||
20 | return nil, err |
||
21 | } |
||
22 | return exporter, nil |
||
23 | } |
||
24 | |||
25 | exporter, err := mexporter.New() |
||
26 | if err != nil { |
||
27 | return nil, err |
||
28 | } |
||
29 | |||
30 | return exporter, nil |
||
31 | } |
||
32 |