2020-03-23 22:41:10 -07:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-09-16 13:58:15 -07:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-11-04 18:10:58 +01:00
|
|
|
package trace // import "go.opentelemetry.io/otel/sdk/trace"
|
2019-09-16 13:58:15 -07:00
|
|
|
|
2019-10-08 20:56:58 +02:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-11-16 18:30:54 +01:00
|
|
|
"go.opentelemetry.io/otel"
|
2019-11-05 13:08:55 -08:00
|
|
|
export "go.opentelemetry.io/otel/sdk/export/trace"
|
2019-10-08 20:56:58 +02:00
|
|
|
)
|
|
|
|
|
2020-09-09 10:19:03 -07:00
|
|
|
// SimpleSpanProcessor is a SpanProcessor that synchronously sends all
|
|
|
|
// SpanData to a trace.Exporter when the span finishes.
|
2019-09-16 13:58:15 -07:00
|
|
|
type SimpleSpanProcessor struct {
|
2020-09-09 10:19:03 -07:00
|
|
|
e export.SpanExporter
|
2019-09-16 13:58:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ SpanProcessor = (*SimpleSpanProcessor)(nil)
|
|
|
|
|
2020-09-09 10:19:03 -07:00
|
|
|
// NewSimpleSpanProcessor returns a new SimpleSpanProcessor that will
|
|
|
|
// synchronously send SpanData to the exporter.
|
|
|
|
func NewSimpleSpanProcessor(exporter export.SpanExporter) *SimpleSpanProcessor {
|
2019-09-16 13:58:15 -07:00
|
|
|
ssp := &SimpleSpanProcessor{
|
2020-09-09 10:19:03 -07:00
|
|
|
e: exporter,
|
2019-09-16 13:58:15 -07:00
|
|
|
}
|
|
|
|
return ssp
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnStart method does nothing.
|
2020-11-16 17:45:49 +01:00
|
|
|
func (ssp *SimpleSpanProcessor) OnStart(parent context.Context, sd *export.SpanData) {
|
2019-09-16 13:58:15 -07:00
|
|
|
}
|
|
|
|
|
2019-10-08 20:56:58 +02:00
|
|
|
// OnEnd method exports SpanData using associated export.
|
|
|
|
func (ssp *SimpleSpanProcessor) OnEnd(sd *export.SpanData) {
|
|
|
|
if ssp.e != nil && sd.SpanContext.IsSampled() {
|
2020-09-09 10:19:03 -07:00
|
|
|
if err := ssp.e.ExportSpans(context.Background(), []*export.SpanData{sd}); err != nil {
|
2020-11-16 18:30:54 +01:00
|
|
|
otel.Handle(err)
|
2020-09-09 10:19:03 -07:00
|
|
|
}
|
2019-09-16 13:58:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown method does nothing. There is no data to cleanup.
|
2020-10-27 05:06:55 +03:00
|
|
|
func (ssp *SimpleSpanProcessor) Shutdown(_ context.Context) error {
|
|
|
|
return nil
|
2019-09-16 13:58:15 -07:00
|
|
|
}
|
2020-09-20 13:35:44 -04:00
|
|
|
|
|
|
|
// ForceFlush does nothing as there is no data to flush.
|
|
|
|
func (ssp *SimpleSpanProcessor) ForceFlush() {
|
|
|
|
}
|