Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Add the ability to close metric and trace clients (#295)
Browse files Browse the repository at this point in the history
* add the ability to close metric and trace clients

Co-authored-by: Punya Biswal <punya@google.com>
  • Loading branch information
dashpole and punya committed Oct 28, 2021
1 parent ed3a404 commit 0a4a840
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,16 @@ func (e *Exporter) StopMetricsExporter() {
e.statsExporter.stopMetricsReader()
}

// Close closes client connections.
func (e *Exporter) Close() error {
tErr := e.traceExporter.close()
mErr := e.statsExporter.close()
if mErr != nil || tErr != nil {
return fmt.Errorf("error(s) closing trace client (%v), or metrics client (%v)", tErr, mErr)
}
return nil
}

// ExportSpan exports a SpanData to Stackdriver Trace.
func (e *Exporter) ExportSpan(sd *trace.SpanData) {
if len(e.traceExporter.o.DefaultTraceAttributes) > 0 {
Expand Down
4 changes: 4 additions & 0 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (e *statsExporter) stopMetricsReader() {
}
}

func (e *statsExporter) close() error {
return e.c.Close()
}

func (e *statsExporter) getMonitoredResource(v *view.View, tags []tag.Tag) ([]tag.Tag, *monitoredrespb.MonitoredResource) {
resource := e.o.Resource
if resource == nil {
Expand Down
4 changes: 4 additions & 0 deletions trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (e *traceExporter) Flush() {
e.bundler.Flush()
}

func (e *traceExporter) close() error {
return e.client.Close()
}

func (e *traceExporter) pushTraceSpans(ctx context.Context, node *commonpb.Node, r *resourcepb.Resource, spans []*trace.SpanData) (int, error) {
ctx, span := trace.StartSpan(
ctx,
Expand Down

0 comments on commit 0a4a840

Please sign in to comment.