Documentation
¶
Index ¶
- Constants
- func DiffCount(count int) attribute.KeyValue
- func DiffCreated(count int) attribute.KeyValue
- func DiffDeleted(count int) attribute.KeyValue
- func DiffReplaced(count int) attribute.KeyValue
- func DiffUpdated(count int) attribute.KeyValue
- func EntrypointCount(count int) attribute.KeyValue
- func EntrypointDirectory(dir string) attribute.KeyValue
- func EntrypointType(epType string) attribute.KeyValue
- func ErrorMessage(msg string) attribute.KeyValue
- func ErrorOccurred(occurred bool) attribute.KeyValue
- func GitBranch(branch string) attribute.KeyValue
- func GitDirectory(dir string) attribute.KeyValue
- func GitHash(hash string) attribute.KeyValue
- func GitPostRef(ref string) attribute.KeyValue
- func GitPreRef(ref string) attribute.KeyValue
- func GitRef(ref string) attribute.KeyValue
- func GitURL(url string) attribute.KeyValue
- func PostDir(dir string) attribute.KeyValue
- func PreDir(dir string) attribute.KeyValue
- func ResourceCount(count int) attribute.KeyValue
- func ResourceName(name string) attribute.KeyValue
- func ResourceType(resType string) attribute.KeyValue
- func WorkingDir(dir string) attribute.KeyValue
- type Span
- type Tracer
Examples ¶
Constants ¶
const ( // Git operation attributes AttrGitURL = "git.url" AttrGitRef = "git.ref" AttrGitBranch = "git.branch" AttrGitHash = "git.hash" AttrGitDirectory = "git.directory" AttrGitPreRef = "git.pre_ref" AttrGitPostRef = "git.post_ref" // Entrypoint attributes AttrEntrypointType = "entrypoint.type" AttrEntrypointDirectory = "entrypoint.directory" AttrEntrypointCount = "entrypoint.count" // Resource attributes AttrResourceType = "resource.type" AttrResourceCount = "resource.count" AttrResourceName = "resource.name" AttrDiffCount = "diff.count" AttrDiffCreated = "diff.created" AttrDiffUpdated = "diff.updated" AttrDiffDeleted = "diff.deleted" AttrDiffReplaced = "diff.replaced" // Directory attributes AttrWorkingDir = "dir.working" AttrPreDir = "dir.pre" AttrPostDir = "dir.post" // Operation result attributes AttrErrorOccurred = "error.occurred" AttrErrorMessage = "error.message" )
Standard attribute keys for gitops operations. These provide consistent naming across the codebase.
Variables ¶
This section is empty.
Functions ¶
func DiffCreated ¶
DiffCreated creates an attribute for created resource count.
func DiffDeleted ¶
DiffDeleted creates an attribute for deleted resource count.
func DiffReplaced ¶
DiffReplaced creates an attribute for replaced resource count.
func DiffUpdated ¶
DiffUpdated creates an attribute for updated resource count.
func EntrypointCount ¶
EntrypointCount creates an attribute for entrypoint count.
func EntrypointDirectory ¶
EntrypointDirectory creates an attribute for entrypoint directory.
func EntrypointType ¶
EntrypointType creates an attribute for entrypoint type.
func ErrorMessage ¶
ErrorMessage creates an attribute for error message.
func ErrorOccurred ¶
ErrorOccurred creates an attribute indicating whether an error occurred.
func GitDirectory ¶
GitDirectory creates an attribute for git directory.
func GitPostRef ¶
GitPostRef creates an attribute for post-change git reference.
func ResourceCount ¶
ResourceCount creates an attribute for resource count.
func ResourceName ¶
ResourceName creates an attribute for resource name.
func ResourceType ¶
ResourceType creates an attribute for resource type.
func WorkingDir ¶
WorkingDir creates an attribute for working directory.
Types ¶
type Span ¶
Span is a convenience wrapper around trace.Span that provides helper methods for common tracing operations.
func (Span) RecordError ¶
RecordError records an error on the span and sets the span status to error. This is a convenience method that combines RecordError and SetStatus.
func (Span) SetAttributes ¶
SetAttributes sets multiple attributes on the span at once.
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer is a wrapper around OpenTelemetry's trace.Tracer interface that provides a simplified API for creating and managing spans.
Example ¶
ExampleTracer demonstrates basic usage of the tracing package.
package main
import (
"context"
"fmt"
"github.com/codingninja/gitops-repo-api/tracing"
)
func main() {
// Create a no-op tracer (tracing disabled)
tracer := tracing.NoOpTracer()
ctx := context.Background()
ctx, span := tracer.Start(ctx, "example.operation")
defer span.End()
// Add attributes to the span
span.SetAttributes(
tracing.GitURL("https://github.com/example/repo"),
tracing.GitRef("main"),
)
fmt.Println("Operation traced")
}
Output: Operation traced
func NewTracer ¶
NewTracer creates a new Tracer instance wrapping the provided trace.Tracer. If tracer is nil, a no-op tracer is used, making tracing optional.
Example ¶
ExampleNewTracer shows how to create a tracer with OpenTelemetry.
package main
import (
"context"
"fmt"
"github.com/codingninja/gitops-repo-api/tracing"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
func main() {
// Create an OpenTelemetry tracer provider
exporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
if err != nil {
panic(err)
}
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithBatcher(exporter),
)
defer tp.Shutdown(context.Background())
// Set as global tracer provider
otel.SetTracerProvider(tp)
// Create a tracer
otelTracer := tp.Tracer("gitops-repo-api")
tracer := tracing.NewTracer(otelTracer)
// Use the tracer
ctx := context.Background()
ctx, span := tracer.Start(ctx, "example.operation")
defer span.End()
fmt.Println("Traced with OpenTelemetry")
}
Output: Traced with OpenTelemetry
func NoOpTracer ¶
func NoOpTracer() *Tracer
NoOpTracer returns a tracer that performs no operations. This is useful for testing or when tracing is disabled.
func (*Tracer) Start ¶
func (t *Tracer) Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
Start creates a new span and returns both the updated context and the span. The span must be ended with span.End() when the operation completes. It's idiomatic to defer span.End() immediately after calling Start.
Example:
ctx, span := tracer.Start(ctx, "operation.name") defer span.End()