Skip to content

Commit

Permalink
fix: rename to ignoreParentDecision
Browse files Browse the repository at this point in the history
  • Loading branch information
karstenkoehler committed Nov 29, 2023
1 parent a97c695 commit f951332
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
67 changes: 40 additions & 27 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,71 @@
# OpenTelemetry
This package provides effective observability to the flamingo ecosystem using the [OpenTelemetry](https://opentelemetry.io/) instrumentation library.
With the OpenTelemetry module, your application automatically exports telemetry data such as metrics and traces.
This makes it easy to analyze your application's behavior and collect statistics about load and performance.
It provides exporters for the most common tools, i.e. Jaeger, Prometheus and OTLP components.

The metrics endpoint is provided under the systemendpoint. Once the module is activate you can access them via `http://localhost:13210/metrics`
This package provides effective observability to the flamingo ecosystem using
the [OpenTelemetry](https://opentelemetry.io/) instrumentation library.
With the OpenTelemetry module, your application automatically exports telemetry data such as metrics and traces.
This makes it easy to analyze your application's behavior and collect statistics about load and performance.
It provides exporters for the most common tools, i.e. Jaeger, Prometheus and OTLP components.

The metrics endpoint is provided under the systemendpoint. Once the module is activate you can access them
via `http://localhost:13210/metrics`

## Module configuration
| Config | Default Value | Description |
|-----------------------------------------------------------|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `flamingo.opentelemetry.serviceName` | `flamingo` | serviceName is automatically added to all traces as `service.name` attribute |
| `flamingo.opentelemetry.jaeger.enable` | `false` | enables the jaeger exporter <br> :information_source: With Jaeger v1.35 they officially support the OpenTelemetry Protocol, so you can use the OTLP exporter instead. |
| `flamingo.opentelemetry.jaeger.endpoint` | `http://localhost:14268/api/traces` | URL to the jaeger instance |
| `flamingo.opentelemetry.zipkin.enable` | `false` | enables the zipkin exporter |
| `flamingo.opentelemetry.zipkin.endpoint` | `http://localhost:9411/api/v2/spans` | URL to the zipkin instance |
| `flamingo.opentelemetry.otlp.http.enable` | `false` | enables the OTLP HTTP exporter |
| `flamingo.opentelemetry.otlp.http.endpoint` | `http://localhost:4318/v1/traces` | URL to the OTLP collector |
| `flamingo.opentelemetry.otlp.grpc.enable` | `false` | enables the OTLP gRPC exporter |
| `flamingo.opentelemetry.otlp.grpc.endpoint` | `grpc://localhost:4317/v1/traces` | URL to the OTLP collector |
| `flamingo.opentelemetry.tracing.sampler.allowlist` | `[]` | list of URL paths that are sampled; if empty, all paths are allowed |
| `flamingo.opentelemetry.tracing.sampler.blocklist` | `[]` | list of URL paths that are never sampled |
| `flamingo.opentelemetry.tracing.sampler.allowParentTrace` | `true` | if `true`, we will follow sampling decisions of the parent span |

| Config | Default Value | Description |
|---------------------------------------------------------------|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `flamingo.opentelemetry.serviceName` | `flamingo` | serviceName is automatically added to all traces as `service.name` attribute |
| `flamingo.opentelemetry.jaeger.enable` | `false` | enables the jaeger exporter <br> :information_source: With Jaeger v1.35 they officially support the OpenTelemetry Protocol, so you can use the OTLP exporter instead. |
| `flamingo.opentelemetry.jaeger.endpoint` | `http://localhost:14268/api/traces` | URL to the jaeger instance |
| `flamingo.opentelemetry.zipkin.enable` | `false` | enables the zipkin exporter |
| `flamingo.opentelemetry.zipkin.endpoint` | `http://localhost:9411/api/v2/spans` | URL to the zipkin instance |
| `flamingo.opentelemetry.otlp.http.enable` | `false` | enables the OTLP HTTP exporter |
| `flamingo.opentelemetry.otlp.http.endpoint` | `http://localhost:4318/v1/traces` | URL to the OTLP collector |
| `flamingo.opentelemetry.otlp.grpc.enable` | `false` | enables the OTLP gRPC exporter |
| `flamingo.opentelemetry.otlp.grpc.endpoint` | `grpc://localhost:4317/v1/traces` | URL to the OTLP collector |
| `flamingo.opentelemetry.tracing.sampler.allowlist` | `[]` | list of URL paths that are sampled; if empty, all paths are allowed |
| `flamingo.opentelemetry.tracing.sampler.blocklist` | `[]` | list of URL paths that are never sampled |
| `flamingo.opentelemetry.tracing.sampler.ignoreParentDecision` | `true` | if `true`, we will ignore sampling decisions of the parent span |

## Adding your own tracing information

Before you can create your own spans, you have to initialize a tracer:

```go
tracer := otel.Tracer("my-app")
```

Now you can create a span based on a `context.Context`. This will automatically attach all tracing-relevant information (e.g. trace-ID) to the span.
Now you can create a span based on a `context.Context`. This will automatically attach all tracing-relevant
information (e.g. trace-ID) to the span.

```go
func doSomething(ctx context.Context) {
ctx, span := tracer.Start(ctx, "my-span")
defer span.End()
// do some work to track with my-span
ctx, span := tracer.Start(ctx, "my-span")
defer span.End()

// do some work to track with my-span
}
```

To add further attributes to the span, please refer to the official [OpenTelemetry documentation](https://opentelemetry.io/docs/instrumentation/go/manual/#traces).
To add further attributes to the span, please refer to the
official [OpenTelemetry documentation](https://opentelemetry.io/docs/instrumentation/go/manual/#traces).

## Adding your own metrics

To collect your own metrics, you have to initialize a meter:

```go
meter := otel.Meter("my-app")
```

Now you can create a new metric, e.g. a counter:

```go
counter, _ := meter.Int64Counter("my.count",
metric.WithDescription("count of something"),
metric.WithDescription("count of something"),
)

counter.Add(ctx, 1)
```

For more information about the kinds of metrics and how to use them, please refer to the official [OpenTelemetry documentation](https://opentelemetry.io/docs/instrumentation/go/manual/#metrics).
For more information about the kinds of metrics and how to use them, please refer to the
official [OpenTelemetry documentation](https://opentelemetry.io/docs/instrumentation/go/manual/#metrics).
2 changes: 1 addition & 1 deletion module.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ flamingo: opentelemetry: {
tracing: sampler: {
allowlist: [...string]
blocklist: [...string]
allowParentTrace: bool | *true
ignoreParentDecision: bool | *true
}
}
`
Expand Down
22 changes: 11 additions & 11 deletions sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import (
)

type ConfiguredURLPrefixSampler struct {
Allowlist config.Slice
Blocklist config.Slice
AllowParentTrace bool
Allowlist config.Slice
Blocklist config.Slice
IgnoreParentDecision bool
}

// Inject dependencies
func (c *ConfiguredURLPrefixSampler) Inject(
cfg *struct {
Allowlist config.Slice `inject:"config:flamingo.opentelemetry.tracing.sampler.allowlist,optional"`
Blocklist config.Slice `inject:"config:flamingo.opentelemetry.tracing.sampler.blocklist,optional"`
AllowParentTrace bool `inject:"config:flamingo.opentelemetry.tracing.sampler.allowParentTrace,optional"`
Allowlist config.Slice `inject:"config:flamingo.opentelemetry.tracing.sampler.allowlist,optional"`
Blocklist config.Slice `inject:"config:flamingo.opentelemetry.tracing.sampler.blocklist,optional"`
IgnoreParentDecision bool `inject:"config:flamingo.opentelemetry.tracing.sampler.ignoreParentDecision,optional"`
},
) *ConfiguredURLPrefixSampler {
if cfg != nil {
c.Allowlist = cfg.Allowlist
c.Blocklist = cfg.Blocklist
c.AllowParentTrace = cfg.AllowParentTrace
c.IgnoreParentDecision = cfg.IgnoreParentDecision
}
return c
}
Expand All @@ -36,10 +36,10 @@ func (c *ConfiguredURLPrefixSampler) GetFilterOption() otelhttp.Filter {
_ = c.Allowlist.MapInto(&allowed)
_ = c.Blocklist.MapInto(&blocked)

return URLPrefixSampler(allowed, blocked, c.AllowParentTrace)
return URLPrefixSampler(allowed, blocked, c.IgnoreParentDecision)
}

func URLPrefixSampler(allowed, blocked []string, allowParentTrace bool) otelhttp.Filter {
func URLPrefixSampler(allowed, blocked []string, ignoreParentDecision bool) otelhttp.Filter {
return func(request *http.Request) bool {
path := request.URL.Path
isParentSampled := trace.SpanContextFromContext(request.Context()).IsSampled()
Expand All @@ -55,7 +55,7 @@ func URLPrefixSampler(allowed, blocked []string, allowParentTrace bool) otelhttp

// we do not sample, unless the parent is sampled
if !sample {
return !allowParentTrace && isParentSampled
return !ignoreParentDecision && isParentSampled
}

// check sampling decision against blocked
Expand All @@ -67,6 +67,6 @@ func URLPrefixSampler(allowed, blocked []string, allowParentTrace bool) otelhttp
}

// we sample, or the parent sampled
return (!allowParentTrace && isParentSampled) || sample
return (!ignoreParentDecision && isParentSampled) || sample
}
}

0 comments on commit f951332

Please sign in to comment.