Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from census-ecosystem/usage-to-README
Browse files Browse the repository at this point in the history
README: add usage example
  • Loading branch information
Emmanuel T Odeke authored Sep 11, 2018
2 parents 05629ac + 4000307 commit 688cc33
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,43 @@ Ultimately we may want to move the OC-Agent Go Exporter to [OpenCensus Go core l
## Installation

```bash
$ go get -u contrib.go.opencensus.io/exporter/ocagent
$ go get -u contrib.go.opencensus.io/exporter/ocagent/v1
```

[OCAgentReadme]: https://github.com/census-instrumentation/opencensus-proto/tree/master/opencensus/proto/agent#opencensus-agent-proto
[OpenCensusGo]: https://github.com/census-instrumentation/opencensus-go

## Usage

```go
import (
"context"
"fmt"
"log"
"time"

"contrib.go.opencensus.io/exporter/ocagent/v1"
"go.opencensus.io/trace"
)

func Example() {
exp, err := ocagent.NewExporter(ocagent.WithInsecure(), ocagent.WithServiceName("your-service-name"))
if err != nil {
log.Fatalf("Failed to create the agent exporter: %v", err)
}
defer exp.Stop()

// Now register it as a trace exporter.
trace.RegisterExporter(exp)

// Then use the OpenCensus tracing library, like we normally would.
ctx, span := trace.StartSpan(context.Background(), "AgentExporter-Example")
defer span.End()

for i := 0; i < 10; i++ {
_, iSpan := trace.StartSpan(ctx, fmt.Sprintf("Sample-%d", i))
<-time.After(6 * time.Millisecond)
iSpan.End()
}
}
```

0 comments on commit 688cc33

Please sign in to comment.