Skip to content
Open
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 .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.24

- name: Build
run: go build -v ./...
Expand Down
53 changes: 32 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![GoDoc](https://img.shields.io/badge/pkg.go.dev-doc-blue)](http://pkg.go.dev/github.com/go-coldbrew/tracing)



# tracing

```go
Expand All @@ -12,27 +14,29 @@ Package tracing is a library that provides distributed tracing to Go application

## Index

- [func ClientSpan(operationName string, ctx context.Context) (context.Context, opentracing.Span)](<#func-clientspan>)
- [func CloneContextValues(parent context.Context) context.Context](<#func-clonecontextvalues>)
- [func GRPCTracingSpan(operationName string, ctx context.Context) context.Context](<#func-grpctracingspan>)
- [func MergeContextValues(parent context.Context, main context.Context) context.Context](<#func-mergecontextvalues>)
- [func MergeParentContext(parent context.Context, main context.Context) context.Context](<#func-mergeparentcontext>)
- [func NewContextWithParentValues(parent context.Context) context.Context](<#func-newcontextwithparentvalues>)
- [type Span](<#type-span>)
- [func NewDatastoreSpan(ctx context.Context, datastore, operation, collection string) (Span, context.Context)](<#func-newdatastorespan>)
- [func NewExternalSpan(ctx context.Context, name string, url string) (Span, context.Context)](<#func-newexternalspan>)
- [func NewHTTPExternalSpan(ctx context.Context, name string, url string, hdr http.Header) (Span, context.Context)](<#func-newhttpexternalspan>)
- [func NewInternalSpan(ctx context.Context, name string) (Span, context.Context)](<#func-newinternalspan>)
- [func ClientSpan\(operationName string, ctx context.Context\) \(context.Context, opentracing.Span, oteltracing.Span\)](<#ClientSpan>)
- [func CloneContextValues\(parent context.Context\) context.Context](<#CloneContextValues>)
- [func GRPCTracingSpan\(operationName string, ctx context.Context\) context.Context](<#GRPCTracingSpan>)
- [func MergeContextValues\(parent context.Context, main context.Context\) context.Context](<#MergeContextValues>)
- [func MergeParentContext\(parent context.Context, main context.Context\) context.Context](<#MergeParentContext>)
- [func NewContextWithParentValues\(parent context.Context\) context.Context](<#NewContextWithParentValues>)
- [type Span](<#Span>)
- [func NewDatastoreSpan\(ctx context.Context, datastore, operation, collection string\) \(Span, context.Context\)](<#NewDatastoreSpan>)
- [func NewExternalSpan\(ctx context.Context, name string, url string\) \(Span, context.Context\)](<#NewExternalSpan>)
- [func NewHTTPExternalSpan\(ctx context.Context, name string, url string, hdr http.Header\) \(Span, context.Context\)](<#NewHTTPExternalSpan>)
- [func NewInternalSpan\(ctx context.Context, name string\) \(Span, context.Context\)](<#NewInternalSpan>)


## func [ClientSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L227>)
<a name="ClientSpan"></a>
## func [ClientSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L321>)

```go
func ClientSpan(operationName string, ctx context.Context) (context.Context, opentracing.Span)
func ClientSpan(operationName string, ctx context.Context) (context.Context, opentracing.Span, oteltracing.Span)
```

ClientSpan starts a new client span linked to the existing spans if any are found in the context. The returned context should be used in place of the original

<a name="CloneContextValues"></a>
## func [CloneContextValues](<https://github.com/go-coldbrew/tracing/blob/main/context.go#L24>)

```go
Expand All @@ -41,14 +45,16 @@ func CloneContextValues(parent context.Context) context.Context

CloneContextValues clones a given context values and returns a new context obj which is not affected by Cancel, Deadline etc Deprecated: The function name is a bit confusing, use CloneContextValues instead

## func [GRPCTracingSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L245>)
<a name="GRPCTracingSpan"></a>
## func [GRPCTracingSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L344>)

```go
func GRPCTracingSpan(operationName string, ctx context.Context) context.Context
```

GRPCTracingSpan starts a new client span linked to the existing spans if any are found in the context. The returned context should be used in place of the original

<a name="MergeContextValues"></a>
## func [MergeContextValues](<https://github.com/go-coldbrew/tracing/blob/main/context.go#L45>)

```go
Expand All @@ -57,6 +63,7 @@ func MergeContextValues(parent context.Context, main context.Context) context.Co

MergeContextValues merged the given main context with a parent context, Cancel/Deadline etc are used from the main context and values are looked in both the contexts can be use to merge a parent context with a new context, the new context will have the values from both the contexts

<a name="MergeParentContext"></a>
## func [MergeParentContext](<https://github.com/go-coldbrew/tracing/blob/main/context.go#L39>)

```go
Expand All @@ -65,6 +72,7 @@ func MergeParentContext(parent context.Context, main context.Context) context.Co

MergeParentContext merged the given main context with a parent context, Cancel/Deadline etc are used from the main context and values are looked in both the contexts Deprecated: The function name is a bit confusing, use MergeContextValues instead

<a name="NewContextWithParentValues"></a>
## func [NewContextWithParentValues](<https://github.com/go-coldbrew/tracing/blob/main/context.go#L30>)

```go
Expand All @@ -73,7 +81,8 @@ func NewContextWithParentValues(parent context.Context) context.Context

NewContextWithParentValues clones a given context values and returns a new context obj which is not affected by Cancel, Deadline etc can be used to pass context values to a new context which is not affected by the parent context cancel/deadline etc from parent

## type [Span](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L19-L30>)
<a name="Span"></a>
## type [Span](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L23-L34>)

Span defines an interface for implementing a tracing span This is used to abstract the underlying tracing implementation, currently using opentracing/opentelemetry and newrelic tracing libraries for implementation

Expand All @@ -92,38 +101,40 @@ type Span interface {
}
```

### func [NewDatastoreSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L126>)
<a name="NewDatastoreSpan"></a>
### func [NewDatastoreSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L189>)

```go
func NewDatastoreSpan(ctx context.Context, datastore, operation, collection string) (Span, context.Context)
```

NewDatastoreSpan starts a span for tracing data store actions This is used to trace actions against a data store, for example, a database query or a redis call

### func [NewExternalSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L178>)
<a name="NewExternalSpan"></a>
### func [NewExternalSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L269>)

```go
func NewExternalSpan(ctx context.Context, name string, url string) (Span, context.Context)
```

NewExternalSpan starts a span for tracing external actions This is used to trace actions against an external service, for example, a call to another service or a call to an external API

### func [NewHTTPExternalSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L185>)
<a name="NewHTTPExternalSpan"></a>
### func [NewHTTPExternalSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L276>)

```go
func NewHTTPExternalSpan(ctx context.Context, name string, url string, hdr http.Header) (Span, context.Context)
```

NewHTTPExternalSpan starts a span for tracing external HTTP actions This is used to trace actions against an external service, for example, a call to another service or a call to an external API It also adds the HTTP headers to the span so that the external service can trace the call back to this service if needed

### func [NewInternalSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L109>)
<a name="NewInternalSpan"></a>
### func [NewInternalSpan](<https://github.com/go-coldbrew/tracing/blob/main/tracing.go#L155>)

```go
func NewInternalSpan(ctx context.Context, name string) (Span, context.Context)
```

NewInternalSpan starts a span for tracing internal actions This is used to trace actions within the same service, for example, a function call within the same service



Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
24 changes: 18 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
module github.com/go-coldbrew/tracing

go 1.15
go 1.24.0

require (
github.com/kr/text v0.2.0 // indirect
github.com/newrelic/go-agent/v3 v3.33.0
github.com/opentracing/opentracing-go v1.2.0
golang.org/x/net v0.26.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
google.golang.org/grpc v1.64.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
go.opentelemetry.io/otel v1.38.0
go.opentelemetry.io/otel/trace v1.38.0
google.golang.org/grpc v1.76.0
)

require (
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/otel/metric v1.38.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.38.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
google.golang.org/protobuf v1.36.8 // indirect
)
Loading