blob: 4ce1881f3b834a3edb19aa6941ed5dec1d5afe32 [file] [log] [blame]
Elia Battistonc8d0d462022-02-22 16:30:51 +01001// Copyright (c) 2017 Uber Technologies, Inc.
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 jaeger
16
17import (
18 opentracing "github.com/opentracing/opentracing-go"
19)
20
21// ContribObserver can be registered with the Tracer to receive notifications
22// about new Spans. Modelled after github.com/opentracing-contrib/go-observer.
23type ContribObserver interface {
24 // Create and return a span observer. Called when a span starts.
25 // If the Observer is not interested in the given span, it must return (nil, false).
26 // E.g :
27 // func StartSpan(opName string, opts ...opentracing.StartSpanOption) {
28 // var sp opentracing.Span
29 // sso := opentracing.StartSpanOptions{}
30 // if spanObserver, ok := Observer.OnStartSpan(span, opName, sso); ok {
31 // // we have a valid SpanObserver
32 // }
33 // ...
34 // }
35 OnStartSpan(sp opentracing.Span, operationName string, options opentracing.StartSpanOptions) (ContribSpanObserver, bool)
36}
37
38// ContribSpanObserver is created by the Observer and receives notifications
39// about other Span events. This interface is meant to match
40// github.com/opentracing-contrib/go-observer, via duck typing, without
41// directly importing the go-observer package.
42type ContribSpanObserver interface {
43 OnSetOperationName(operationName string)
44 OnSetTag(key string, value interface{})
45 OnFinish(options opentracing.FinishOptions)
46}
47
48// wrapper observer for the old observers (see observer.go)
49type oldObserver struct {
50 obs Observer
51}
52
53func (o *oldObserver) OnStartSpan(sp opentracing.Span, operationName string, options opentracing.StartSpanOptions) (ContribSpanObserver, bool) {
54 spanObserver := o.obs.OnStartSpan(operationName, options)
55 return spanObserver, spanObserver != nil
56}