Skip to content

Commit e063557

Browse files
authored
Add new localstack tracer to return tracing headers set by invoke (#31)
1 parent a252c82 commit e063557

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

cmd/localstack/main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func main() {
178178

179179
logCollector := NewLogCollector()
180180
localStackLogsEgressApi := NewLocalStackLogsEgressAPI(logCollector)
181+
tracer := NewLocalStackTracer()
181182

182183
// build sandbox
183184
sandbox := rapidcore.
@@ -191,7 +192,8 @@ func main() {
191192
}).
192193
SetExtensionsFlag(true).
193194
SetInitCachingFlag(true).
194-
SetLogsEgressAPI(localStackLogsEgressApi)
195+
SetLogsEgressAPI(localStackLogsEgressApi).
196+
SetTracer(tracer)
195197

196198
// xray daemon
197199
endpoint := "http://" + lsOpts.LocalstackIP + ":" + lsOpts.EdgePort

cmd/localstack/tracer.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"go.amzn.com/lambda/appctx"
7+
"go.amzn.com/lambda/interop"
8+
)
9+
10+
type LocalStackTracer struct {
11+
invoke *interop.Invoke
12+
}
13+
14+
func (t *LocalStackTracer) Configure(invoke *interop.Invoke) {
15+
t.invoke = invoke
16+
}
17+
18+
func (t *LocalStackTracer) CaptureInvokeSegment(ctx context.Context, criticalFunction func(context.Context) error) error {
19+
return criticalFunction(ctx)
20+
}
21+
22+
func (t *LocalStackTracer) CaptureInitSubsegment(ctx context.Context, criticalFunction func(context.Context) error) error {
23+
return criticalFunction(ctx)
24+
}
25+
26+
func (t *LocalStackTracer) CaptureInvokeSubsegment(ctx context.Context, criticalFunction func(context.Context) error) error {
27+
return criticalFunction(ctx)
28+
}
29+
30+
func (t *LocalStackTracer) CaptureOverheadSubsegment(ctx context.Context, criticalFunction func(context.Context) error) error {
31+
return criticalFunction(ctx)
32+
}
33+
34+
func (t *LocalStackTracer) RecordInitStartTime() {}
35+
func (t *LocalStackTracer) RecordInitEndTime() {}
36+
func (t *LocalStackTracer) SendInitSubsegmentWithRecordedTimesOnce(ctx context.Context) {}
37+
func (t *LocalStackTracer) SendRestoreSubsegmentWithRecordedTimesOnce(ctx context.Context) {}
38+
func (t *LocalStackTracer) MarkError(ctx context.Context) {}
39+
func (t *LocalStackTracer) AttachErrorCause(ctx context.Context, errorCause json.RawMessage) {}
40+
41+
func (t *LocalStackTracer) WithErrorCause(ctx context.Context, appCtx appctx.ApplicationContext, criticalFunction func(ctx context.Context) error) func(ctx context.Context) error {
42+
return criticalFunction
43+
}
44+
func (t *LocalStackTracer) WithError(ctx context.Context, appCtx appctx.ApplicationContext, criticalFunction func(ctx context.Context) error) func(ctx context.Context) error {
45+
return criticalFunction
46+
}
47+
func (t *LocalStackTracer) BuildTracingHeader() func(context.Context) string {
48+
// extract root trace ID and parent from context and build the tracing header
49+
return func(ctx context.Context) string {
50+
return t.invoke.TraceID
51+
}
52+
}
53+
54+
func (t *LocalStackTracer) BuildTracingCtxForStart() *interop.TracingCtx {
55+
return nil
56+
}
57+
func (t *LocalStackTracer) BuildTracingCtxAfterInvokeComplete() *interop.TracingCtx {
58+
return nil
59+
}
60+
61+
func NewLocalStackTracer() *LocalStackTracer {
62+
return &LocalStackTracer{}
63+
}

0 commit comments

Comments
 (0)