/
tracing.go
40 lines (30 loc) · 1.38 KB
/
tracing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package pubsubapi
import (
"context"
"github.com/estafette/estafette-ci-api/pkg/api"
manifest "github.com/estafette/estafette-ci-manifest"
"github.com/opentracing/opentracing-go"
)
// NewTracingClient returns a new instance of a tracing Client.
func NewTracingClient(c Client) Client {
return &tracingClient{c, "pubsubapi"}
}
type tracingClient struct {
Client Client
prefix string
}
func (c *tracingClient) SubscriptionForTopic(ctx context.Context, message PubSubPushMessage) (event *manifest.EstafettePubSubEvent, err error) {
span, ctx := opentracing.StartSpanFromContext(ctx, api.GetSpanName(c.prefix, "SubscriptionForTopic"))
defer func() { api.FinishSpanWithError(span, err) }()
return c.Client.SubscriptionForTopic(ctx, message)
}
func (c *tracingClient) SubscribeToTopic(ctx context.Context, projectID, topicID string) (err error) {
span, ctx := opentracing.StartSpanFromContext(ctx, api.GetSpanName(c.prefix, "SubscribeToTopic"))
defer func() { api.FinishSpanWithError(span, err) }()
return c.Client.SubscribeToTopic(ctx, projectID, topicID)
}
func (c *tracingClient) SubscribeToPubsubTriggers(ctx context.Context, manifestString string) (err error) {
span, ctx := opentracing.StartSpanFromContext(ctx, api.GetSpanName(c.prefix, "SubscribeToPubsubTriggers"))
defer func() { api.FinishSpanWithError(span, err) }()
return c.Client.SubscribeToPubsubTriggers(ctx, manifestString)
}