Skip to content

Commit

Permalink
feat: add otel resource loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Jan 7, 2025
1 parent d78baf1 commit 05c9eba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
19 changes: 17 additions & 2 deletions internal/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/go-faster/sdk/zctx"
"github.com/spf13/cobra"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
"go.uber.org/zap"

"github.com/go-faster/simon/internal/app"
Expand Down Expand Up @@ -47,7 +49,7 @@ func cmdClient() *cobra.Command {
ticker := time.NewTicker(time.Second)
tracer := t.TracerProvider().Tracer("")
tick := func() {
ctx, cancel := context.WithTimeout(ctx, time.Second)
ctx, cancel := context.WithTimeout(ctx, time.Millisecond*250)
defer cancel()

ctx, span := tracer.Start(ctx, "client.tick")
Expand All @@ -72,7 +74,20 @@ func cmdClient() *cobra.Command {
tick()
}
}
})
},
sdka.WithResource(func(ctx context.Context) (*resource.Resource, error) {
return resource.New(ctx,
resource.WithOS(),
resource.WithFromEnv(),
resource.WithTelemetrySDK(),
resource.WithHost(),
resource.WithProcess(),
resource.WithAttributes(
attribute.String("service.name", "simon.client"),
),
)
}),
)
},
}
}
17 changes: 16 additions & 1 deletion internal/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/rs/cors"
"github.com/spf13/cobra"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"

Expand Down Expand Up @@ -105,7 +107,20 @@ func cmdServer() *cobra.Command {
return nil
})
return g.Wait()
})
},
sdka.WithResource(func(ctx context.Context) (*resource.Resource, error) {
return resource.New(ctx,
resource.WithOS(),
resource.WithFromEnv(),
resource.WithTelemetrySDK(),
resource.WithHost(),
resource.WithProcess(),
resource.WithAttributes(
attribute.String("service.name", "simon.server"),
),
)
}),
)
},
}
}

0 comments on commit 05c9eba

Please sign in to comment.