1// Copyright The OpenTelemetry Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package trace // import "go.opentelemetry.io/otel/sdk/trace"
16
17import (
18	"context"
19
20	"go.opentelemetry.io/otel"
21	export "go.opentelemetry.io/otel/sdk/export/trace"
22)
23
24// SimpleSpanProcessor is a SpanProcessor that synchronously sends all
25// SpanData to a trace.Exporter when the span finishes.
26type SimpleSpanProcessor struct {
27	e export.SpanExporter
28}
29
30var _ SpanProcessor = (*SimpleSpanProcessor)(nil)
31
32// NewSimpleSpanProcessor returns a new SimpleSpanProcessor that will
33// synchronously send SpanData to the exporter.
34func NewSimpleSpanProcessor(exporter export.SpanExporter) *SimpleSpanProcessor {
35	ssp := &SimpleSpanProcessor{
36		e: exporter,
37	}
38	return ssp
39}
40
41// OnStart method does nothing.
42func (ssp *SimpleSpanProcessor) OnStart(parent context.Context, sd *export.SpanData) {
43}
44
45// OnEnd method exports SpanData using associated export.
46func (ssp *SimpleSpanProcessor) OnEnd(sd *export.SpanData) {
47	if ssp.e != nil && sd.SpanContext.IsSampled() {
48		if err := ssp.e.ExportSpans(context.Background(), []*export.SpanData{sd}); err != nil {
49			otel.Handle(err)
50		}
51	}
52}
53
54// Shutdown method does nothing. There is no data to cleanup.
55func (ssp *SimpleSpanProcessor) Shutdown(_ context.Context) error {
56	return nil
57}
58
59// ForceFlush does nothing as there is no data to flush.
60func (ssp *SimpleSpanProcessor) ForceFlush() {
61}
62