| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package log // import "go.opentelemetry.io/otel/sdk/log" |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"fmt" |
| 9 |
|
| 10 |
"go.opentelemetry.io/otel" |
| 11 |
"go.opentelemetry.io/otel/metric" |
| 12 |
"go.opentelemetry.io/otel/sdk" |
| 13 |
"go.opentelemetry.io/otel/sdk/log/internal/x" |
| 14 |
semconv "go.opentelemetry.io/otel/semconv/v1.40.0" |
| 15 |
"go.opentelemetry.io/otel/semconv/v1.40.0/otelconv" |
| 16 |
) |
| 17 |
|
| 18 |
// newRecordCounterIncr returns a function that increments the log record |
| 19 |
// counter metric. If observability is disabled, it returns nil. |
| 20 |
func newRecordCounterIncr() (func(context.Context), error) { |
| 21 |
if !x.Observability.Enabled() { |
| 22 |
return nil, nil |
| 23 |
} |
| 24 |
|
| 25 |
m := otel.GetMeterProvider().Meter( |
| 26 |
"go.opentelemetry.io/otel/sdk/log", |
| 27 |
metric.WithInstrumentationVersion(sdk.Version()), |
| 28 |
metric.WithSchemaURL(semconv.SchemaURL), |
| 29 |
) |
| 30 |
|
| 31 |
created, err := otelconv.NewSDKLogCreated(m) |
| 32 |
if err != nil { |
| 33 |
err = fmt.Errorf("failed to create log created metric: %w", err) |
| 34 |
return nil, err |
| 35 |
} |
| 36 |
inst := created.Inst() |
| 37 |
f := func(ctx context.Context) { inst.Add(ctx, 1) } |
| 38 |
return f, nil |
| 39 |
} |