Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit e87afd9

Browse files
author
Bogdan Drutu
authored
Change FormatName to [Trace|Metrics]FormatName to be able to use as tags. (#463)
1 parent 2c8c2ec commit e87afd9

File tree

8 files changed

+55
-34
lines changed

8 files changed

+55
-34
lines changed

exporter/exportertest/nop_exporter.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ func (ne *nopExporter) ProcessMetricsData(ctx context.Context, md data.MetricsDa
3434
return nil
3535
}
3636

37-
const nopExportFormat = "NopExporter"
37+
const (
38+
nopTraceExportFormat = "nop_trace"
39+
nopMetricsExportFormat = "nop_metrics"
40+
)
41+
42+
func (ne *nopExporter) TraceExportFormat() string {
43+
return nopTraceExportFormat
44+
}
3845

39-
func (ne *nopExporter) ExportFormat() string {
40-
return nopExportFormat
46+
func (ne *nopExporter) MetricsExportFormat() string {
47+
return nopMetricsExportFormat
4148
}
4249

4350
// NewNopTraceExporter creates an TraceExporter that just drops the received data.

exporter/exportertest/nop_exporter_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func TestNopTraceExporterNoErrors(t *testing.T) {
3131
t.Errorf("Wanted nil got error")
3232
return
3333
}
34-
if "NopExporter" != nte.ExportFormat() {
35-
t.Errorf("Wanted NopExporter got %s", nte.ExportFormat())
34+
if "nop_trace" != nte.TraceExportFormat() {
35+
t.Errorf("Wanted nop_trace got %s", nte.TraceExportFormat())
3636
return
3737
}
3838
}
@@ -46,8 +46,8 @@ func TestNoopMetricsExporterNoErrors(t *testing.T) {
4646
t.Errorf("Wanted nil got error")
4747
return
4848
}
49-
if "NopExporter" != nme.ExportFormat() {
50-
t.Errorf("Wanted NopExporter got %s", nme.ExportFormat())
49+
if "nop_metrics" != nme.MetricsExportFormat() {
50+
t.Errorf("Wanted nop_metrics got %s", nme.MetricsExportFormat())
5151
return
5252
}
5353
}

exporter/exportertest/sink_exporter.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ func (ste *SinkTraceExporter) ProcessTraceData(ctx context.Context, td data.Trac
4040
return nil
4141
}
4242

43-
const sinkExportFormat = "SinkExporter"
43+
const (
44+
sinkTraceExportFormat = "sink_trace"
45+
sinkMetricsExportFormat = "sink_metrics"
46+
)
4447

45-
// ExportFormat retruns the name of this TraceExporter
46-
func (ste *SinkTraceExporter) ExportFormat() string {
47-
return sinkExportFormat
48+
// TraceExportFormat retruns the name of this TraceExporter
49+
func (ste *SinkTraceExporter) TraceExportFormat() string {
50+
return sinkTraceExportFormat
4851
}
4952

5053
// AllTraces returns the traces sent to the test sink.
@@ -73,9 +76,9 @@ func (sme *SinkMetricsExporter) ProcessMetricsData(ctx context.Context, md data.
7376
return nil
7477
}
7578

76-
// ExportFormat retruns the name of this TraceExporter
77-
func (sme *SinkMetricsExporter) ExportFormat() string {
78-
return sinkExportFormat
79+
// MetricsExportFormat retruns the name of this MetricsExporter
80+
func (sme *SinkMetricsExporter) MetricsExportFormat() string {
81+
return sinkMetricsExportFormat
7982
}
8083

8184
// AllMetrics returns the metrics sent to the test sink.

exporter/exportertest/sink_exporter_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func TestSinkTraceExporter(t *testing.T) {
4040
if !reflect.DeepEqual(got, want) {
4141
t.Errorf("Mismatches responses\nGot:\n\t%v\nWant:\n\t%v\n", got, want)
4242
}
43-
if "SinkExporter" != sink.ExportFormat() {
44-
t.Errorf("Wanted SinkExporter got %s", sink.ExportFormat())
43+
if "sink_trace" != sink.TraceExportFormat() {
44+
t.Errorf("Wanted sink_trace got %s", sink.TraceExportFormat())
4545
return
4646
}
4747
}
@@ -63,8 +63,8 @@ func TestSinkMetricsExporter(t *testing.T) {
6363
if !reflect.DeepEqual(got, want) {
6464
t.Errorf("Mismatches responses\nGot:\n\t%v\nWant:\n\t%v\n", got, want)
6565
}
66-
if "SinkExporter" != sink.ExportFormat() {
67-
t.Errorf("Wanted SinkExporter got %s", sink.ExportFormat())
66+
if "sink_metrics" != sink.MetricsExportFormat() {
67+
t.Errorf("Wanted sink_metrics got %s", sink.MetricsExportFormat())
6868
return
6969
}
7070
}

exporter/factory.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import (
2727
type TraceExporter interface {
2828
processor.TraceDataProcessor
2929

30-
// ExportFormat gets the name of the format in which this exporter sends its data.
31-
ExportFormat() string
30+
// TraceExportFormat gets the name of the format in which this exporter sends its data.
31+
// For exporters that can export multiple signals it is recommended to encode the signal
32+
// as suffix (e.g. "oc_trace").
33+
TraceExportFormat() string
3234
}
3335

3436
// TraceExporterFactory is an interface that builds a new TraceExporter based on
@@ -50,8 +52,10 @@ type TraceExporterFactory interface {
5052
type MetricsExporter interface {
5153
processor.MetricsDataProcessor
5254

53-
// ExportFormat gets the name of the format in which this exporter sends its data.
54-
ExportFormat() string
55+
// MetricsExportFormat gets the name of the format in which this exporter sends its data.
56+
// For exporters that can export multiple signals it is recommended to encode the signal
57+
// as suffix (e.g. "oc_metrics").
58+
MetricsExportFormat() string
5559
}
5660

5761
// MetricsExporterFactory is an interface that builds a new MetricsExporter based on

exporter/loggingexporter/logging_exporter.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import (
2323
"go.uber.org/zap"
2424
)
2525

26-
const exportFormat = "LoggingExporter"
26+
const (
27+
traceExportFormat = "logging_trace"
28+
metricsExportFormat = "logging_metrics"
29+
)
2730

2831
// A logging exporter that does not sends the data to any destination but logs debugging messages.
2932
type loggingExporter struct{ logger *zap.Logger }
@@ -36,7 +39,7 @@ func (le *loggingExporter) ProcessTraceData(ctx context.Context, td data.TraceDa
3639
// TODO: Add ability to record the received data
3740

3841
// Even though we just log all the spans, we record 0 dropped spans.
39-
observability.RecordTraceExporterMetrics(observability.ContextWithExporterName(ctx, "logging_trace"), len(td.Spans), 0)
42+
observability.RecordTraceExporterMetrics(observability.ContextWithExporterName(ctx, traceExportFormat), len(td.Spans), 0)
4043
return nil
4144
}
4245

@@ -47,8 +50,12 @@ func (le *loggingExporter) ProcessMetricsData(ctx context.Context, md data.Metri
4750
return nil
4851
}
4952

50-
func (le *loggingExporter) ExportFormat() string {
51-
return exportFormat
53+
func (le *loggingExporter) TraceExportFormat() string {
54+
return traceExportFormat
55+
}
56+
57+
func (le *loggingExporter) MetricsExportFormat() string {
58+
return metricsExportFormat
5259
}
5360

5461
// NewTraceExporter creates an exporter.TraceExporter that just drops the

exporter/loggingexporter/logging_exporter_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ func TestLoggingTraceExporterNoErrors(t *testing.T) {
3333
t.Errorf("Wanted nil got error")
3434
return
3535
}
36-
if "LoggingExporter" != lte.ExportFormat() {
37-
t.Errorf("Wanted LoggingExporter got %v", lte.ExportFormat())
36+
if "logging_trace" != lte.TraceExportFormat() {
37+
t.Errorf("Wanted logging_trace got %v", lte.TraceExportFormat())
3838
}
3939
}
4040

4141
func TestLoggingTraceExporterRecordMetrics(t *testing.T) {
4242
lte := NewTraceExporter(zap.NewNop())
43-
observabilitytest.CheckRecordedMetricsForTraceExporter(t, lte, "logging_trace")
43+
observabilitytest.CheckRecordedMetricsForTraceExporter(t, lte)
4444
}
4545

4646
func TestLoggingMetricsExporterNoErrors(t *testing.T) {
@@ -52,7 +52,7 @@ func TestLoggingMetricsExporterNoErrors(t *testing.T) {
5252
t.Errorf("Wanted nil got error")
5353
return
5454
}
55-
if "LoggingExporter" != lme.ExportFormat() {
56-
t.Errorf("Wanted LoggingExporter got %v", lme.ExportFormat())
55+
if "logging_metrics" != lme.MetricsExportFormat() {
56+
t.Errorf("Wanted logging_metrics got %v", lme.MetricsExportFormat())
5757
}
5858
}

observability/observabilitytest/observabilitytest.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (cme *nopMetricsExporter) ExportView(vd *view.Data) {}
4343

4444
// CheckRecordedMetricsForTraceExporter checks that the given TraceExporter records the correct set of metrics with the correct
4545
// set of tags by sending some TraceData to the exporter. The exporter should be able to handle the requests.
46-
func CheckRecordedMetricsForTraceExporter(t *testing.T, te exporter.TraceExporter, exporterTagName string) {
46+
func CheckRecordedMetricsForTraceExporter(t *testing.T, te exporter.TraceExporter) {
4747
// Register a nop metrics exporter for the OC library.
4848
nmp := new(nopMetricsExporter)
4949
view.RegisterExporter(nmp)
@@ -98,8 +98,8 @@ func CheckRecordedMetricsForTraceExporter(t *testing.T, te exporter.TraceExporte
9898
}
9999
}
100100

101-
checkValueForExporterView(t, observability.ViewExporterReceivedSpans, exporterTagName, int64(numBatches*len(spans)))
102-
checkValueForExporterView(t, observability.ViewExporterDroppedSpans, exporterTagName, 0)
101+
checkValueForExporterView(t, observability.ViewExporterReceivedSpans, te.TraceExportFormat(), int64(numBatches*len(spans)))
102+
checkValueForExporterView(t, observability.ViewExporterDroppedSpans, te.TraceExportFormat(), 0)
103103
}
104104

105105
func checkValueForExporterView(t *testing.T, v *view.View, exporterTagName string, value int64) {

0 commit comments

Comments
 (0)