Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otel: add project_name and is_user_service attributes #2255

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildengine/testdata/type_registry_main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/ftl-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
kctx.FatalIfErrorf(err, "failed to create encryptors")

ctx := log.ContextWithLogger(context.Background(), log.Configure(os.Stderr, cli.LogConfig))
err = observability.Init(ctx, "ftl-controller", ftl.Version, cli.ObservabilityConfig)
err = observability.Init(ctx, false, "", "ftl-controller", ftl.Version, cli.ObservabilityConfig)
kctx.FatalIfErrorf(err, "failed to initialize observability")

// The FTL controller currently only supports DB as a configuration provider/resolver.
Expand Down
2 changes: 1 addition & 1 deletion cmd/ftl-runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ and route to user code.
})
logger := log.Configure(os.Stderr, cli.LogConfig)
ctx := log.ContextWithLogger(context.Background(), logger)
err = observability.Init(ctx, "ftl-runner", ftl.Version, cli.ObservabilityConfig)
err = observability.Init(ctx, false, "", "ftl-runner", ftl.Version, cli.ObservabilityConfig)
kctx.FatalIfErrorf(err, "failed to initialize observability")
err = runner.Start(ctx, cli.RunnerConfig)
kctx.FatalIfErrorf(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/ftl/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *serveCmd) run(ctx context.Context, projConfig projectconfig.Config, ini
return err
}

err = observability.Init(ctx, "ftl-serve", ftl.Version, s.ObservabilityConfig)
err = observability.Init(ctx, false, "", "ftl-serve", ftl.Version, s.ObservabilityConfig)
if err != nil {
return fmt.Errorf("observability init failed: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
{{- end}}

func main() {
verbConstructor := server.NewUserVerbServer("{{.Name}}",
verbConstructor := server.NewUserVerbServer("{{.ProjectName}}", "{{.Name}}",
{{- range .Verbs}}
{{- if and .HasRequest .HasResponse}}
server.HandleCall({{.Package}}.{{.Name}}),
Expand Down
12 changes: 12 additions & 0 deletions go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/common/moduleconfig"
"github.com/TBD54566975/ftl/common/projectconfig"
extract "github.com/TBD54566975/ftl/go-runtime/schema"
"github.com/TBD54566975/ftl/internal"
"github.com/TBD54566975/ftl/internal/exec"
Expand Down Expand Up @@ -59,6 +60,7 @@ type mainModuleContext struct {
GoVersion string
FTLVersion string
Name string
ProjectName string
SharedModulesPaths []string
Verbs []goVerb
Replacements []*modfile.Replace
Expand Down Expand Up @@ -123,6 +125,15 @@ func Build(ctx context.Context, projectRootDir, moduleDir string, sch *schema.Sc
ftlVersion = ftl.Version
}

projectName := ""
if pcpath, ok := projectconfig.DefaultConfigPath().Get(); ok {
pc, err := projectconfig.Load(ctx, pcpath)
if err != nil {
return fmt.Errorf("failed to load project config: %w", err)
}
projectName = pc.Name
}

config, err := moduleconfig.LoadModuleConfig(moduleDir)
if err != nil {
return fmt.Errorf("failed to load module config: %w", err)
Expand Down Expand Up @@ -203,6 +214,7 @@ func Build(ctx context.Context, projectRootDir, moduleDir string, sch *schema.Sc
GoVersion: goModVersion,
FTLVersion: ftlVersion,
Name: result.Module.Name,
ProjectName: projectName,
SharedModulesPaths: sharedModulesPaths,
Verbs: goVerbs,
Replacements: replacements,
Expand Down
4 changes: 2 additions & 2 deletions go-runtime/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type UserVerbConfig struct {
// NewUserVerbServer starts a new code-generated drive for user Verbs.
//
// This function is intended to be used by the code generator.
func NewUserVerbServer(moduleName string, handlers ...Handler) plugin.Constructor[ftlv1connect.VerbServiceHandler, UserVerbConfig] {
func NewUserVerbServer(projectName string, moduleName string, handlers ...Handler) plugin.Constructor[ftlv1connect.VerbServiceHandler, UserVerbConfig] {
return func(ctx context.Context, uc UserVerbConfig) (context.Context, ftlv1connect.VerbServiceHandler, error) {
verbServiceClient := rpc.Dial(ftlv1connect.NewVerbServiceClient, uc.FTLEndpoint.String(), log.Error)
ctx = rpc.ContextWithClient(ctx, verbServiceClient)
Expand All @@ -45,7 +45,7 @@ func NewUserVerbServer(moduleName string, handlers ...Handler) plugin.Constructo
ctx = dynamicCtx.ApplyToContext(ctx)
ctx = internal.WithContext(ctx, internal.New(dynamicCtx))

err = observability.Init(ctx, moduleName, "HEAD", uc.ObservabilityConfig)
err = observability.Init(ctx, true, projectName, moduleName, "HEAD", uc.ObservabilityConfig)
if err != nil {
return nil, nil, fmt.Errorf("could not initialize metrics: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion internal/observability/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/propagation"
Expand Down Expand Up @@ -34,7 +35,7 @@ type Config struct {
ExportOTEL ExportOTELFlag `help:"Export observability data to OTEL." env:"OTEL_EXPORTER_OTLP_ENDPOINT"`
}

func Init(ctx context.Context, serviceName, serviceVersion string, config Config) error {
func Init(ctx context.Context, isUserService bool, projectName, serviceName, serviceVersion string, config Config) error {
logger := log.FromContext(ctx)
if !config.ExportOTEL {
logger.Tracef("OTEL export is disabled, set OTEL_EXPORTER_OTLP_ENDPOINT to enable")
Expand All @@ -52,6 +53,8 @@ func Init(ctx context.Context, serviceName, serviceVersion string, config Config
schemaURL,
semconv.ServiceName(serviceName),
semconv.ServiceVersion(serviceVersion),
attribute.Bool("ftl.is_user_service", isUserService),
attribute.String("ftl.project_name", projectName),
))
if err != nil {
return fmt.Errorf("failed to create OTEL resource: %w", err)
Expand Down
Loading