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

Commit 0a4a840

Browse files
dashpolepunya
andauthored
Add the ability to close metric and trace clients (#295)
* add the ability to close metric and trace clients Co-authored-by: Punya Biswal <[email protected]>
1 parent ed3a404 commit 0a4a840

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

stackdriver.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ func (e *Exporter) StopMetricsExporter() {
435435
e.statsExporter.stopMetricsReader()
436436
}
437437

438+
// Close closes client connections.
439+
func (e *Exporter) Close() error {
440+
tErr := e.traceExporter.close()
441+
mErr := e.statsExporter.close()
442+
if mErr != nil || tErr != nil {
443+
return fmt.Errorf("error(s) closing trace client (%v), or metrics client (%v)", tErr, mErr)
444+
}
445+
return nil
446+
}
447+
438448
// ExportSpan exports a SpanData to Stackdriver Trace.
439449
func (e *Exporter) ExportSpan(sd *trace.SpanData) {
440450
if len(e.traceExporter.o.DefaultTraceAttributes) > 0 {

stats.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ func (e *statsExporter) stopMetricsReader() {
149149
}
150150
}
151151

152+
func (e *statsExporter) close() error {
153+
return e.c.Close()
154+
}
155+
152156
func (e *statsExporter) getMonitoredResource(v *view.View, tags []tag.Tag) ([]tag.Tag, *monitoredrespb.MonitoredResource) {
153157
resource := e.o.Resource
154158
if resource == nil {

trace.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func (e *traceExporter) Flush() {
120120
e.bundler.Flush()
121121
}
122122

123+
func (e *traceExporter) close() error {
124+
return e.client.Close()
125+
}
126+
123127
func (e *traceExporter) pushTraceSpans(ctx context.Context, node *commonpb.Node, r *resourcepb.Resource, spans []*trace.SpanData) (int, error) {
124128
ctx, span := trace.StartSpan(
125129
ctx,

0 commit comments

Comments
 (0)