Skip to content

Commit

Permalink
implement factory and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencl1013 committed Jul 13, 2020
1 parent 120c4ff commit 32b8f93
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
20 changes: 15 additions & 5 deletions exporter/stackdriverexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
package stackdriverexporter

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/config/configmodels"
"go.uber.org/zap"
//"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -45,13 +48,20 @@ func (f *Factory) CreateDefaultConfig() configmodels.Exporter {
}

// CreateTraceExporter creates a trace exporter based on this config.
func (f *Factory) CreateTraceExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.TraceExporter, error) {
func (f *Factory) CreateTraceExporter(
_ context.Context,
_ component.ExporterCreateParams,
cfg configmodels.Exporter) (component.TraceExporter, error) {
eCfg := cfg.(*Config)
return newStackdriverTraceExporter(eCfg)
}

// CreateMetricsExporter creates a metrics exporter based on this config.
func (f *Factory) CreateMetricsExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.MetricsExporterOld, error) {
eCfg := cfg.(*Config)
return newStackdriverMetricsExporter(eCfg)
func (f *Factory) CreateMetricsExporter(
_ context.Context,
_ component.ExporterCreateParams,
cfg configmodels.Exporter) (component.MetricsExporter, error) {
// eCfg := cfg.(*Config)
// return newStackdriverMetricsExporter(eCfg)
return nil, configerror.ErrDataTypeIsNotSupported
}
15 changes: 10 additions & 5 deletions exporter/stackdriverexporter/spandata.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func pdataSpanToOTSpanData(
resource pdata.Resource,
il pdata.InstrumentationLibrary,
) (*export.SpanData, error) {
if span.IsNil() {
return nil, errNilSpan
}
sc := apitrace.SpanContext{}
copy(sc.TraceID[:], span.TraceID())
copy(sc.SpanID[:], span.SpanID())
Expand All @@ -104,10 +107,7 @@ func pdataSpanToOTSpanData(
startTime := time.Unix(0, int64(span.StartTime()))
endTime := time.Unix(0, int64(span.EndTime()))
status := span.Status()
instrumentationLibrary := instrumentation.Library{
Name: il.Name(),
Version: il.Version(),
}

sd := &export.SpanData{
SpanContext: sc,
ParentSpanID: parentSpanID,
Expand All @@ -126,7 +126,12 @@ func pdataSpanToOTSpanData(
DroppedAttributeCount: int(span.DroppedAttributesCount()),
DroppedMessageEventCount: int(span.DroppedEventsCount()),
DroppedLinkCount: int(span.DroppedLinksCount()),
InstrumentationLibrary: instrumentationLibrary,
}
if !il.IsNil() {
sd.InstrumentationLibrary = instrumentation.Library{
Name: il.Name(),
Version: il.Version(),
}
}

return sd, nil
Expand Down
2 changes: 1 addition & 1 deletion exporter/stackdriverexporter/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@ func (se *stackdriverExporter) newPushTraceData(ctx context.Context, td pdata.Tr
se.texporter.ExportSpan(ctx, span)
goodSpans++
}

fmt.Println("Good spans:", goodSpans)
return numSpans - goodSpans, componenterror.CombineErrors(errs)
}

0 comments on commit 32b8f93

Please sign in to comment.