Skip to content

Commit 47bb8ca

Browse files
authored
Add otel_project_id flag for GCP local runs (#325)
1 parent 070df95 commit 47bb8ca

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

cmd/gcp/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ import (
2828
"syscall"
2929
"time"
3030

31-
"github.com/transparency-dev/tesseract"
32-
"github.com/transparency-dev/tesseract/storage"
33-
"github.com/transparency-dev/tesseract/storage/gcp"
3431
"github.com/transparency-dev/tessera"
3532
tgcp "github.com/transparency-dev/tessera/storage/gcp"
3633
gcp_as "github.com/transparency-dev/tessera/storage/gcp/antispam"
34+
"github.com/transparency-dev/tesseract"
35+
"github.com/transparency-dev/tesseract/storage"
36+
"github.com/transparency-dev/tesseract/storage/gcp"
3737
"golang.org/x/mod/sumdb/note"
3838
"k8s.io/klog/v2"
3939
)
@@ -64,6 +64,7 @@ var (
6464
signerPublicKeySecretName = flag.String("signer_public_key_secret_name", "", "Public key secret name for checkpoints and SCTs signer. Format: projects/{projectId}/secrets/{secretName}/versions/{secretVersion}.")
6565
signerPrivateKeySecretName = flag.String("signer_private_key_secret_name", "", "Private key secret name for checkpoints and SCTs signer. Format: projects/{projectId}/secrets/{secretName}/versions/{secretVersion}.")
6666
traceFraction = flag.Float64("trace_fraction", 0, "Fraction of open-telemetry span traces to sample")
67+
otelProjectID = flag.String("otel_project_id", "", "GCP project ID for OpenTelemetry exporter. This is only required for local runs.")
6768
)
6869

6970
// nolint:staticcheck
@@ -72,7 +73,7 @@ func main() {
7273
flag.Parse()
7374
ctx := context.Background()
7475

75-
shutdownOTel := initOTel(ctx, *traceFraction, *origin)
76+
shutdownOTel := initOTel(ctx, *traceFraction, *origin, *otelProjectID)
7677
defer shutdownOTel(ctx)
7778

7879
signer, err := NewSecretManagerSigner(ctx, *signerPublicKeySecretName, *signerPrivateKeySecretName)

cmd/gcp/otel.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
//
3535
// Tracing is enabled with statistical sampling, with the probability passed in.
3636
// Returns a shutdown function which should be called just before exiting the process.
37-
func initOTel(ctx context.Context, traceFraction float64, origin string) func(context.Context) {
37+
func initOTel(ctx context.Context, traceFraction float64, origin string, projectID string) func(context.Context) {
3838
var shutdownFuncs []func(context.Context) error
3939
// shutdown combines shutdown functions from multiple OpenTelemetry
4040
// components into a single function.
@@ -63,7 +63,11 @@ func initOTel(ctx context.Context, traceFraction float64, origin string) func(co
6363
klog.Exitf("Failed to detect resources: %v", err)
6464
}
6565

66-
me, err := mexporter.New()
66+
mopts := []mexporter.Option{}
67+
if projectID != "" {
68+
mopts = append(mopts, mexporter.WithProjectID(projectID))
69+
}
70+
me, err := mexporter.New(mopts...)
6771
if err != nil {
6872
klog.Exitf("Failed to create metric exporter: %v", err)
6973
return nil
@@ -76,7 +80,11 @@ func initOTel(ctx context.Context, traceFraction float64, origin string) func(co
7680
shutdownFuncs = append(shutdownFuncs, mp.Shutdown)
7781
otel.SetMeterProvider(mp)
7882

79-
te, err := texporter.New()
83+
topts := []texporter.Option{}
84+
if projectID != "" {
85+
topts = append(topts, texporter.WithProjectID(projectID))
86+
}
87+
te, err := texporter.New(topts...)
8088
if err != nil {
8189
klog.Exitf("Failed to create trace exporter: %v", err)
8290
return nil

0 commit comments

Comments
 (0)