Skip to content

Commit

Permalink
Add ability to also discover PubSub
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBergmeier6176 committed Apr 29, 2024
1 parent 6e9ab65 commit 8727607
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/gcp/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type discoveryOption struct {
namespace string
pod string
gkeAutoDiscoverMetaData bool
discoverPubSub bool
}

func WithKubernetes(clusterName, namespace, pod, containerName string) discoveryOption {
Expand All @@ -58,6 +59,12 @@ func WithKubernetes(clusterName, namespace, pod, containerName string) discovery
}
}

func WithPubSub() discoveryOption {
return discoveryOption{
discoverPubSub: true,
}
}

func WithGKEAutoDiscoverMetaData() discoveryOption {
/*
This option will try to auto discover available metadata from the Google Cloud metadata service and environment variables.
Expand Down Expand Up @@ -118,6 +125,7 @@ func DiscoverServices(project, serviceName string, tracerProviderOptions []sdktr
ErrorReporting: errorClient,
}

discoverPubSub := false
var traceResource *resource.Resource
for _, opt := range opts {
if opt.gkeAutoDiscoverMetaData {
Expand All @@ -134,11 +142,19 @@ func DiscoverServices(project, serviceName string, tracerProviderOptions []sdktr
traceResource = gke.TraceResourceFromMetaData(serviceName, metadata)
} else if opt.pod != "" {
s.MonitoredResource = gke.MonitoredResource(s.Logging, project, opt.clusterName, opt.namespace, opt.pod, opt.containerName)
} else if opt.discoverPubSub {
discoverPubSub = true
}
}
if traceResource != nil {
tracerProviderOptions = append(tracerProviderOptions, sdktrace.WithResource(traceResource))
}
if discoverPubSub {
s.PubSub, err = pubsub.NewClient(context.Background(), project)
if err != nil {
return nil, err
}
}

s.TracerProvider = sdktrace.NewTracerProvider(append(tracerProviderOptions, sdktrace.WithBatcher(exporter))...)

Expand Down

0 comments on commit 8727607

Please sign in to comment.