Skip to content

Commit 1ac08c1

Browse files
committed
rename aibridge -> tracing
1 parent 7760d31 commit 1ac08c1

16 files changed

+124
-124
lines changed

intercept_anthropic_messages_base.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"github.com/anthropics/anthropic-sdk-go/option"
1515
"github.com/aws/aws-sdk-go-v2/config"
1616
"github.com/aws/aws-sdk-go-v2/credentials"
17-
aibtrace "github.com/coder/aibridge/aibtrace"
1817
"github.com/coder/aibridge/mcp"
18+
"github.com/coder/aibridge/tracing"
1919
"github.com/google/uuid"
2020
"go.opentelemetry.io/otel/attribute"
2121
"go.opentelemetry.io/otel/trace"
@@ -65,13 +65,13 @@ func (i *AnthropicMessagesInterceptionBase) Model() string {
6565

6666
func (s *AnthropicMessagesInterceptionBase) baseTraceAttributes(r *http.Request, streaming bool) []attribute.KeyValue {
6767
return []attribute.KeyValue{
68-
attribute.String(aibtrace.RequestPath, r.URL.Path),
69-
attribute.String(aibtrace.InterceptionID, s.id.String()),
70-
attribute.String(aibtrace.InitiatorID, actorFromContext(r.Context()).id),
71-
attribute.String(aibtrace.Provider, ProviderAnthropic),
72-
attribute.String(aibtrace.Model, s.Model()),
73-
attribute.Bool(aibtrace.Streaming, streaming),
74-
attribute.Bool(aibtrace.IsBedrock, s.bedrockCfg != nil),
68+
attribute.String(tracing.RequestPath, r.URL.Path),
69+
attribute.String(tracing.InterceptionID, s.id.String()),
70+
attribute.String(tracing.InitiatorID, actorFromContext(r.Context()).id),
71+
attribute.String(tracing.Provider, ProviderAnthropic),
72+
attribute.String(tracing.Model, s.Model()),
73+
attribute.Bool(tracing.Streaming, streaming),
74+
attribute.Bool(tracing.IsBedrock, s.bedrockCfg != nil),
7575
}
7676
}
7777

intercept_anthropic_messages_blocking.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"go.opentelemetry.io/otel/attribute"
1515
"go.opentelemetry.io/otel/trace"
1616

17-
aibtrace "github.com/coder/aibridge/aibtrace"
1817
"github.com/coder/aibridge/mcp"
18+
"github.com/coder/aibridge/tracing"
1919

2020
"cdr.dev/slog"
2121
)
@@ -53,8 +53,8 @@ func (i *AnthropicMessagesBlockingInterception) ProcessRequest(w http.ResponseWr
5353
return fmt.Errorf("developer error: req is nil")
5454
}
5555

56-
ctx, span := i.tracer.Start(r.Context(), "Intercept.ProcessRequest", trace.WithAttributes(aibtrace.InterceptionAttributesFromContext(r.Context())...))
57-
defer aibtrace.EndSpanErr(span, &outErr)
56+
ctx, span := i.tracer.Start(r.Context(), "Intercept.ProcessRequest", trace.WithAttributes(tracing.InterceptionAttributesFromContext(r.Context())...))
57+
defer tracing.EndSpanErr(span, &outErr)
5858

5959
i.injectTools()
6060

@@ -298,8 +298,8 @@ func (i *AnthropicMessagesBlockingInterception) ProcessRequest(w http.ResponseWr
298298
}
299299

300300
func (i *AnthropicMessagesBlockingInterception) traceNewMessage(ctx context.Context, svc anthropic.MessageService, msgParams anthropic.MessageNewParams) (_ *anthropic.Message, outErr error) {
301-
ctx, span := i.tracer.Start(ctx, "Intercept.ProcessRequest.Upstream", trace.WithAttributes(aibtrace.InterceptionAttributesFromContext(ctx)...))
302-
defer aibtrace.EndSpanErr(span, &outErr)
301+
ctx, span := i.tracer.Start(ctx, "Intercept.ProcessRequest.Upstream", trace.WithAttributes(tracing.InterceptionAttributesFromContext(ctx)...))
302+
defer tracing.EndSpanErr(span, &outErr)
303303

304304
return svc.New(ctx, msgParams)
305305
}

intercept_anthropic_messages_streaming.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"github.com/anthropics/anthropic-sdk-go"
1414
"github.com/anthropics/anthropic-sdk-go/packages/ssestream"
1515
"github.com/anthropics/anthropic-sdk-go/shared/constant"
16-
aibtrace "github.com/coder/aibridge/aibtrace"
1716
"github.com/coder/aibridge/mcp"
17+
"github.com/coder/aibridge/tracing"
1818
"github.com/google/uuid"
1919
mcplib "github.com/mark3labs/mcp-go/mcp"
2020
"go.opentelemetry.io/otel/attribute"
@@ -75,8 +75,8 @@ func (i *AnthropicMessagesStreamingInterception) ProcessRequest(w http.ResponseW
7575
return fmt.Errorf("developer error: req is nil")
7676
}
7777

78-
ctx, span := i.tracer.Start(r.Context(), "Intercept.ProcessRequest", trace.WithAttributes(aibtrace.InterceptionAttributesFromContext(r.Context())...))
79-
defer aibtrace.EndSpanErr(span, &outErr)
78+
ctx, span := i.tracer.Start(r.Context(), "Intercept.ProcessRequest", trace.WithAttributes(tracing.InterceptionAttributesFromContext(r.Context())...))
79+
defer tracing.EndSpanErr(span, &outErr)
8080

8181
// Allow us to interrupt watch via cancel.
8282
ctx, cancel := context.WithCancel(ctx)
@@ -523,7 +523,7 @@ func (s *AnthropicMessagesStreamingInterception) encodeForStream(payload []byte,
523523
}
524524

525525
func (s *AnthropicMessagesStreamingInterception) traceNewStreaming(ctx context.Context, svc anthropic.MessageService, messages anthropic.MessageNewParams) *ssestream.Stream[anthropic.MessageStreamEventUnion] {
526-
_, span := s.tracer.Start(ctx, "Intercept.ProcessRequest.Upstream", trace.WithAttributes(aibtrace.InterceptionAttributesFromContext(ctx)...))
526+
_, span := s.tracer.Start(ctx, "Intercept.ProcessRequest.Upstream", trace.WithAttributes(tracing.InterceptionAttributesFromContext(ctx)...))
527527
defer span.End()
528528

529529
return svc.NewStreaming(ctx, messages)

intercept_openai_chat_base.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"encoding/json"
66
"net/http"
77

8-
aibtrace "github.com/coder/aibridge/aibtrace"
98
"github.com/coder/aibridge/mcp"
9+
"github.com/coder/aibridge/tracing"
1010
"github.com/google/uuid"
1111
"github.com/openai/openai-go/v2"
1212
"github.com/openai/openai-go/v2/option"
@@ -48,12 +48,12 @@ func (i *OpenAIChatInterceptionBase) Setup(logger slog.Logger, recorder Recorder
4848

4949
func (s *OpenAIChatInterceptionBase) baseTraceAttributes(r *http.Request, streaming bool) []attribute.KeyValue {
5050
return []attribute.KeyValue{
51-
attribute.String(aibtrace.RequestPath, r.URL.Path),
52-
attribute.String(aibtrace.InterceptionID, s.id.String()),
53-
attribute.String(aibtrace.InitiatorID, actorFromContext(r.Context()).id),
54-
attribute.String(aibtrace.Provider, ProviderOpenAI),
55-
attribute.String(aibtrace.Model, s.Model()),
56-
attribute.Bool(aibtrace.Streaming, streaming),
51+
attribute.String(tracing.RequestPath, r.URL.Path),
52+
attribute.String(tracing.InterceptionID, s.id.String()),
53+
attribute.String(tracing.InitiatorID, actorFromContext(r.Context()).id),
54+
attribute.String(tracing.Provider, ProviderOpenAI),
55+
attribute.String(tracing.Model, s.Model()),
56+
attribute.Bool(tracing.Streaming, streaming),
5757
}
5858
}
5959

intercept_openai_chat_blocking.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"strings"
99
"time"
1010

11-
aibtrace "github.com/coder/aibridge/aibtrace"
1211
"github.com/coder/aibridge/mcp"
12+
"github.com/coder/aibridge/tracing"
1313
"github.com/google/uuid"
1414
"github.com/openai/openai-go/v2"
1515
"github.com/openai/openai-go/v2/option"
@@ -52,8 +52,8 @@ func (i *OpenAIBlockingChatInterception) ProcessRequest(w http.ResponseWriter, r
5252
return fmt.Errorf("developer error: req is nil")
5353
}
5454

55-
ctx, span := i.tracer.Start(r.Context(), "Intercept.ProcessRequest", trace.WithAttributes(aibtrace.InterceptionAttributesFromContext(r.Context())...))
56-
defer aibtrace.EndSpanErr(span, &outErr)
55+
ctx, span := i.tracer.Start(r.Context(), "Intercept.ProcessRequest", trace.WithAttributes(tracing.InterceptionAttributesFromContext(r.Context())...))
56+
defer tracing.EndSpanErr(span, &outErr)
5757

5858
svc := i.newCompletionsService(i.baseURL, i.key)
5959
logger := i.logger.With(slog.F("model", i.req.Model))
@@ -233,8 +233,8 @@ func (i *OpenAIBlockingChatInterception) ProcessRequest(w http.ResponseWriter, r
233233
}
234234

235235
func (i *OpenAIBlockingChatInterception) traceChatCompletionsNew(ctx context.Context, svc openai.ChatCompletionService, opts []option.RequestOption) (_ *openai.ChatCompletion, outErr error) {
236-
ctx, span := i.tracer.Start(ctx, "Intercept.ProcessRequest.Upstream", trace.WithAttributes(aibtrace.InterceptionAttributesFromContext(ctx)...))
237-
defer aibtrace.EndSpanErr(span, &outErr)
236+
ctx, span := i.tracer.Start(ctx, "Intercept.ProcessRequest.Upstream", trace.WithAttributes(tracing.InterceptionAttributesFromContext(ctx)...))
237+
defer tracing.EndSpanErr(span, &outErr)
238238

239239
return svc.New(ctx, i.req.ChatCompletionNewParams, opts...)
240240
}

intercept_openai_chat_streaming.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"strings"
1111
"time"
1212

13-
aibtrace "github.com/coder/aibridge/aibtrace"
1413
"github.com/coder/aibridge/mcp"
14+
"github.com/coder/aibridge/tracing"
1515
"github.com/google/uuid"
1616
"github.com/openai/openai-go/v2"
1717
"github.com/openai/openai-go/v2/packages/ssestream"
@@ -67,8 +67,8 @@ func (i *OpenAIStreamingChatInterception) ProcessRequest(w http.ResponseWriter,
6767
return fmt.Errorf("developer error: req is nil")
6868
}
6969

70-
ctx, span := i.tracer.Start(r.Context(), "Intercept.ProcessRequest", trace.WithAttributes(aibtrace.InterceptionAttributesFromContext(r.Context())...))
71-
defer aibtrace.EndSpanErr(span, &outErr)
70+
ctx, span := i.tracer.Start(r.Context(), "Intercept.ProcessRequest", trace.WithAttributes(tracing.InterceptionAttributesFromContext(r.Context())...))
71+
defer tracing.EndSpanErr(span, &outErr)
7272

7373
// Include token usage.
7474
i.req.StreamOptions.IncludeUsage = openai.Bool(true)
@@ -347,7 +347,7 @@ func (i *OpenAIStreamingChatInterception) encodeForStream(payload []byte) []byte
347347
}
348348

349349
func (i *OpenAIStreamingChatInterception) traceNewStreaming(ctx context.Context, svc openai.ChatCompletionService) *ssestream.Stream[openai.ChatCompletionChunk] {
350-
_, span := i.tracer.Start(ctx, "Intercept.ProcessRequest.Upstream", trace.WithAttributes(aibtrace.InterceptionAttributesFromContext(ctx)...))
350+
_, span := i.tracer.Start(ctx, "Intercept.ProcessRequest.Upstream", trace.WithAttributes(tracing.InterceptionAttributesFromContext(ctx)...))
351351
defer span.End()
352352

353353
return svc.NewStreaming(ctx, i.req.ChatCompletionNewParams)

interception.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"time"
99

1010
"cdr.dev/slog"
11-
aibtrace "github.com/coder/aibridge/aibtrace"
1211
"github.com/coder/aibridge/mcp"
12+
"github.com/coder/aibridge/tracing"
1313
"github.com/google/uuid"
1414
"go.opentelemetry.io/otel/attribute"
1515
"go.opentelemetry.io/otel/codes"
@@ -69,7 +69,7 @@ func newInterceptionProcessor(p Provider, logger slog.Logger, recorder Recorder,
6969

7070
traceAttrs := interceptor.TraceAttributes(r)
7171
span.SetAttributes(traceAttrs...)
72-
ctx = aibtrace.WithInterceptionAttributesInContext(ctx, traceAttrs)
72+
ctx = tracing.WithInterceptionAttributesInContext(ctx, traceAttrs)
7373
r = r.WithContext(ctx)
7474

7575
// Record usage in the background to not block request flow.

mcp/proxy_streamable_http.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99

1010
"cdr.dev/slog"
11-
"github.com/coder/aibridge/aibtrace"
11+
"github.com/coder/aibridge/tracing"
1212
"github.com/mark3labs/mcp-go/client"
1313
"github.com/mark3labs/mcp-go/client/transport"
1414
"github.com/mark3labs/mcp-go/mcp"
@@ -60,7 +60,7 @@ func (p *StreamableHTTPServerProxy) Name() string {
6060

6161
func (p *StreamableHTTPServerProxy) Init(ctx context.Context) (outErr error) {
6262
ctx, span := p.tracer.Start(ctx, "StreamableHTTPServerProxy.Init", trace.WithAttributes(p.traceAttributes()...))
63-
defer aibtrace.EndSpanErr(span, &outErr)
63+
defer tracing.EndSpanErr(span, &outErr)
6464

6565
if err := p.client.Start(ctx); err != nil {
6666
return fmt.Errorf("start client: %w", err)
@@ -134,7 +134,7 @@ func (p *StreamableHTTPServerProxy) CallTool(ctx context.Context, name string, i
134134

135135
func (p *StreamableHTTPServerProxy) fetchTools(ctx context.Context) (_ map[string]*Tool, outErr error) {
136136
ctx, span := p.tracer.Start(ctx, "StreamableHTTPServerProxy.Init.fetchTools", trace.WithAttributes(p.traceAttributes()...))
137-
defer aibtrace.EndSpanErr(span, &outErr)
137+
defer tracing.EndSpanErr(span, &outErr)
138138

139139
tools, err := p.client.ListTools(ctx, mcp.ListToolsRequest{})
140140
if err != nil {
@@ -156,7 +156,7 @@ func (p *StreamableHTTPServerProxy) fetchTools(ctx context.Context) (_ map[strin
156156
Logger: p.logger,
157157
}
158158
}
159-
span.SetAttributes(append(p.traceAttributes(), attribute.Int(aibtrace.MCPToolCount, len(out)))...)
159+
span.SetAttributes(append(p.traceAttributes(), attribute.Int(tracing.MCPToolCount, len(out)))...)
160160
return out, nil
161161
}
162162

@@ -172,8 +172,8 @@ func (p *StreamableHTTPServerProxy) Shutdown(ctx context.Context) error {
172172

173173
func (p *StreamableHTTPServerProxy) traceAttributes() []attribute.KeyValue {
174174
return []attribute.KeyValue{
175-
attribute.String(aibtrace.MCPProxyName, p.Name()),
176-
attribute.String(aibtrace.MCPServerName, p.serverName),
177-
attribute.String(aibtrace.MCPServerURL, p.serverURL),
175+
attribute.String(tracing.MCPProxyName, p.Name()),
176+
attribute.String(tracing.MCPServerName, p.serverName),
177+
attribute.String(tracing.MCPServerURL, p.serverURL),
178178
}
179179
}

mcp/server_proxy_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88
"sync"
99

10-
"github.com/coder/aibridge/aibtrace"
10+
"github.com/coder/aibridge/tracing"
1111
"github.com/coder/aibridge/utils"
1212
"github.com/mark3labs/mcp-go/mcp"
1313
"go.opentelemetry.io/otel/trace"
@@ -50,7 +50,7 @@ func (s *ServerProxyManager) addTools(tools []*Tool) {
5050
// Init concurrently initializes all of its [ServerProxier]s.
5151
func (s *ServerProxyManager) Init(ctx context.Context) (outErr error) {
5252
ctx, span := s.tracer.Start(ctx, "ServerProxyManager.Init")
53-
defer aibtrace.EndSpanErr(span, &outErr)
53+
defer tracing.EndSpanErr(span, &outErr)
5454

5555
cg := utils.NewConcurrentGroup()
5656
for _, proxy := range s.proxiers {

mcp/tool.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99

1010
"cdr.dev/slog"
11-
"github.com/coder/aibridge/aibtrace"
11+
"github.com/coder/aibridge/tracing"
1212
"github.com/mark3labs/mcp-go/mcp"
1313
"go.opentelemetry.io/otel/attribute"
1414
"go.opentelemetry.io/otel/trace"
@@ -49,10 +49,10 @@ func (t *Tool) Call(ctx context.Context, tracer trace.Tracer, input any) (_ *mcp
4949
}
5050

5151
spanAttrs := append(
52-
aibtrace.InterceptionAttributesFromContext(ctx),
53-
attribute.String(aibtrace.MCPToolName, t.Name),
54-
attribute.String(aibtrace.MCPServerName, t.ServerName),
55-
attribute.String(aibtrace.MCPServerURL, t.ServerURL),
52+
tracing.InterceptionAttributesFromContext(ctx),
53+
attribute.String(tracing.MCPToolName, t.Name),
54+
attribute.String(tracing.MCPServerName, t.ServerName),
55+
attribute.String(tracing.MCPServerURL, t.ServerURL),
5656
)
5757
inputJson, err := json.Marshal(input)
5858
if err != nil {
@@ -62,11 +62,11 @@ func (t *Tool) Call(ctx context.Context, tracer trace.Tracer, input any) (_ *mcp
6262
if len(strJson) > maxSpanInputAttrLen {
6363
strJson = strJson[:100]
6464
}
65-
spanAttrs = append(spanAttrs, attribute.String(aibtrace.MCPInput, strJson))
65+
spanAttrs = append(spanAttrs, attribute.String(tracing.MCPInput, strJson))
6666
}
6767

6868
ctx, span := tracer.Start(ctx, "Intercept.ProcessRequest.ToolCall", trace.WithAttributes(spanAttrs...))
69-
defer aibtrace.EndSpanErr(span, &outErr)
69+
defer tracing.EndSpanErr(span, &outErr)
7070

7171
return t.Client.CallTool(ctx, mcp.CallToolRequest{
7272
Params: mcp.CallToolParams{

0 commit comments

Comments
 (0)