Skip to content

Commit f611ac3

Browse files
committed
Fixing issue from creating / generator complete golang restfulapi
1 parent ef81427 commit f611ac3

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ RUN /telemetryflow-gen version && /telemetryflow-restapi version
7070
# -----------------------------------------------------------------------------
7171
# Stage 2: Runtime
7272
# -----------------------------------------------------------------------------
73-
FROM alpine:3.21
73+
FROM alpine:3.23
7474

7575
# =============================================================================
7676
# TelemetryFlow Metadata Labels (OCI Image Spec)

docs/GENERATOR_RESTAPI.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ Templates support the following helper functions:
510510
| `replace` | Replace string | `{{replace .Name "-" "_"}}` |
511511
| `trimSuffix` | Trim suffix | `{{trimSuffix .Name "_id"}}` |
512512
| `trimPrefix` | Trim prefix | `{{trimPrefix .Name "tbl_"}}` |
513+
| `add` | Add numbers | `{{add 1 2}}` → `3` |
513514

514515
## Custom Templates
515516

@@ -533,6 +534,7 @@ type TemplateData struct {
533534
ServiceName string
534535
ServiceVersion string
535536
Environment string
537+
EnvPrefix string // Environment variable prefix (e.g., ORDER_SERVICE)
536538
537539
// Database
538540
DBDriver string

pkg/telemetryflow/client.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,24 +197,14 @@ func (c *Client) LogError(ctx context.Context, message string, attributes map[st
197197

198198
// ===== TRACES API =====
199199

200-
// StartSpan starts a new trace span
200+
// StartSpan starts a new trace span and returns the span ID
201201
func (c *Client) StartSpan(ctx context.Context, name string, kind string, attributes map[string]interface{}) (string, error) {
202202
if !c.isInitialized() {
203203
return "", fmt.Errorf("client not initialized")
204204
}
205205

206-
cmd := &application.StartSpanCommand{
207-
Name: name,
208-
Kind: kind,
209-
Attributes: attributes,
210-
}
211-
212-
if err := c.commandHandler.Handle(ctx, cmd); err != nil {
213-
return "", err
214-
}
215-
216-
// In production, return the actual span ID
217-
return "span-id-placeholder", nil
206+
// Use the direct method that returns the span ID
207+
return c.commandHandler.StartSpanDirect(ctx, name, kind, attributes)
218208
}
219209

220210
// EndSpan ends an active span

pkg/telemetryflow/infrastructure/handlers.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,17 @@ func (h *TelemetryCommandHandler) handleEmitLog(ctx context.Context, cmd *applic
297297

298298
// ===== TRACE HANDLERS =====
299299

300-
func (h *TelemetryCommandHandler) handleStartSpan(ctx context.Context, cmd *application.StartSpanCommand) error {
300+
// StartSpanDirect starts a new span and returns its ID directly
301+
// This is the preferred method for starting spans as it returns the span ID
302+
func (h *TelemetryCommandHandler) StartSpanDirect(ctx context.Context, name string, kind string, attributes map[string]interface{}) (string, error) {
301303
if !h.initialized || h.tracer == nil {
302-
return fmt.Errorf("traces not initialized")
304+
return "", fmt.Errorf("traces not initialized")
303305
}
304306

305-
attrs := convertAttributes(cmd.Attributes)
307+
attrs := convertAttributes(attributes)
306308

307309
var spanKind trace.SpanKind
308-
switch cmd.Kind {
310+
switch kind {
309311
case "internal":
310312
spanKind = trace.SpanKindInternal
311313
case "server":
@@ -320,7 +322,7 @@ func (h *TelemetryCommandHandler) handleStartSpan(ctx context.Context, cmd *appl
320322
spanKind = trace.SpanKindInternal
321323
}
322324

323-
_, span := h.tracer.Start(ctx, cmd.Name,
325+
_, span := h.tracer.Start(ctx, name,
324326
trace.WithSpanKind(spanKind),
325327
trace.WithAttributes(attrs...),
326328
)
@@ -331,7 +333,12 @@ func (h *TelemetryCommandHandler) handleStartSpan(ctx context.Context, cmd *appl
331333
h.activeSpans[spanID] = span
332334
h.spansMutex.Unlock()
333335

334-
return nil
336+
return spanID, nil
337+
}
338+
339+
func (h *TelemetryCommandHandler) handleStartSpan(ctx context.Context, cmd *application.StartSpanCommand) error {
340+
_, err := h.StartSpanDirect(ctx, cmd.Name, cmd.Kind, cmd.Attributes)
341+
return err
335342
}
336343

337344
func (h *TelemetryCommandHandler) handleEndSpan(ctx context.Context, cmd *application.EndSpanCommand) error {

0 commit comments

Comments
 (0)