1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-17 01:12:45 +02:00

Replace spaces to tabs in Go code snippets (#1854)

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Robert Pająk
2021-04-28 17:19:15 +02:00
committed by GitHub
parent cb0972504e
commit d4c8ffadad
4 changed files with 48 additions and 48 deletions

View File

@ -180,7 +180,7 @@ specific type name this Configuration applies to if there are multiple
```go ```go
// config contains configuration options for a thing. // config contains configuration options for a thing.
type config struct { type config struct {
// options ... // options ...
} }
``` ```
@ -200,13 +200,13 @@ all options to create a configured `config`.
```go ```go
// newConfig returns an appropriately configured config. // newConfig returns an appropriately configured config.
func newConfig([]Option) config { func newConfig([]Option) config {
// Set default values for config. // Set default values for config.
config := config{/* […] */} config := config{/* […] */}
for _, option := range options { for _, option := range options {
option.apply(&config) option.apply(&config)
} }
// Preform any validation here. // Preform any validation here.
return config return config
} }
``` ```
@ -224,7 +224,7 @@ To set the value of the options a `config` contains, a corresponding
```go ```go
type Option interface { type Option interface {
apply(*config) apply(*config)
} }
``` ```
@ -255,12 +255,12 @@ func With*(…) Option { … }
type defaultFalseOption bool type defaultFalseOption bool
func (o defaultFalseOption) apply(c *config) { func (o defaultFalseOption) apply(c *config) {
c.Bool = bool(o) c.Bool = bool(o)
} }
// WithOption sets a T to have an option included. // WithOption sets a T to have an option included.
func WithOption() Option { func WithOption() Option {
return defaultFalseOption(true) return defaultFalseOption(true)
} }
``` ```
@ -268,12 +268,12 @@ func WithOption() Option {
type defaultTrueOption bool type defaultTrueOption bool
func (o defaultTrueOption) apply(c *config) { func (o defaultTrueOption) apply(c *config) {
c.Bool = bool(o) c.Bool = bool(o)
} }
// WithoutOption sets a T to have Bool option excluded. // WithoutOption sets a T to have Bool option excluded.
func WithoutOption() Option { func WithoutOption() Option {
return defaultTrueOption(false) return defaultTrueOption(false)
} }
``` ```
@ -281,16 +281,16 @@ func WithoutOption() Option {
```go ```go
type myTypeOption struct { type myTypeOption struct {
MyType MyType MyType MyType
} }
func (o myTypeOption) apply(c *config) { func (o myTypeOption) apply(c *config) {
c.MyType = o.MyType c.MyType = o.MyType
} }
// WithMyType sets T to have include MyType. // WithMyType sets T to have include MyType.
func WithMyType(t MyType) Option { func WithMyType(t MyType) Option {
return myTypeOption{t} return myTypeOption{t}
} }
``` ```
@ -317,25 +317,25 @@ For example.
```go ```go
// config holds options for all animals. // config holds options for all animals.
type config struct { type config struct {
Weight float64 Weight float64
Color string Color string
MaxAltitude float64 MaxAltitude float64
} }
// DogOption apply Dog specific options. // DogOption apply Dog specific options.
type DogOption interface { type DogOption interface {
applyDog(*config) applyDog(*config)
} }
// BirdOption apply Bird specific options. // BirdOption apply Bird specific options.
type BirdOption interface { type BirdOption interface {
applyBird(*config) applyBird(*config)
} }
// Option apply options for all animals. // Option apply options for all animals.
type Option interface { type Option interface {
BirdOption BirdOption
DogOption DogOption
} }
type weightOption float64 type weightOption float64

View File

@ -10,7 +10,7 @@ In a perfect world, one would simply migrate their entire go application --inclu
However, if you create the following spans in a go application: However, if you create the following spans in a go application:
```golang ```go
ctx, ocSpan := opencensus.StartSpan(context.Background(), "OuterSpan") ctx, ocSpan := opencensus.StartSpan(context.Background(), "OuterSpan")
defer ocSpan.End() defer ocSpan.End()
ctx, otSpan := opentelemetryTracer.Start(ctx, "MiddleSpan") ctx, otSpan := opentelemetryTracer.Start(ctx, "MiddleSpan")
@ -54,11 +54,11 @@ Starting from an application using entirely OpenCensus APIs:
4. Remove OpenCensus exporters and configuration 4. Remove OpenCensus exporters and configuration
To override OpenCensus' DefaultTracer with the bridge: To override OpenCensus' DefaultTracer with the bridge:
```golang ```go
import ( import (
octrace "go.opencensus.io/trace" octrace "go.opencensus.io/trace"
"go.opentelemetry.io/otel/bridge/opencensus" "go.opentelemetry.io/otel/bridge/opencensus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
) )
tracer := otel.GetTracerProvider().Tracer("bridge") tracer := otel.GetTracerProvider().Tracer("bridge")
@ -102,12 +102,12 @@ Starting from an application using entirely OpenCensus APIs:
4. Remove OpenCensus Exporters and configuration. 4. Remove OpenCensus Exporters and configuration.
For example, to swap out the OpenCensus logging exporter for the OpenTelemetry stdout exporter: For example, to swap out the OpenCensus logging exporter for the OpenTelemetry stdout exporter:
```golang ```go
import ( import (
"go.opencensus.io/metric/metricexport" "go.opencensus.io/metric/metricexport"
"go.opentelemetry.io/otel/bridge/opencensus" "go.opentelemetry.io/otel/bridge/opencensus"
"go.opentelemetry.io/otel/exporters/stdout" "go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
) )
// With OpenCensus, you could have previously configured the logging exporter like this: // With OpenCensus, you could have previously configured the logging exporter like this:
// import logexporter "go.opencensus.io/examples/exporter" // import logexporter "go.opencensus.io/examples/exporter"

View File

@ -13,7 +13,7 @@ A sampler needs to be set on the tracer provider when its configured, as follows
```go ```go
provider := sdktrace.NewTracerProvider( provider := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()), sdktrace.WithSampler(sdktrace.AlwaysSample()),
) )
``` ```
@ -34,14 +34,14 @@ Resources should be assigned to a tracer provider at its initialization, and are
```go ```go
resources := resource.New( resources := resource.New(
attribute.String("service.name", "myService"), attribute.String("service.name", "myService"),
attribute.String("service.version", "1.0.0"), attribute.String("service.version", "1.0.0"),
attribute.String("instance.id", "abcdef12345"), attribute.String("instance.id", "abcdef12345"),
) )
provider := sdktrace.NewTracerProvider( provider := sdktrace.NewTracerProvider(
... ...
sdktrace.WithResources(resources), sdktrace.WithResources(resources),
) )
``` ```

View File

@ -21,20 +21,20 @@ In Go, the `context` package is used to store the active span. When you start a
```go ```go
func parentFunction() { func parentFunction() {
ctx := context.Background() ctx := context.Background()
var parentSpan trace.Span var parentSpan trace.Span
ctx, parentSpan = tracer.Start(ctx, "parent") ctx, parentSpan = tracer.Start(ctx, "parent")
defer parentSpan.End() defer parentSpan.End()
// call our child function // call our child function
childFunction(ctx) childFunction(ctx)
// do more work, when this function ends, parentSpan will complete. // do more work, when this function ends, parentSpan will complete.
} }
func childFunction(ctx context.Context) { func childFunction(ctx context.Context) {
var childSpan trace.Span var childSpan trace.Span
ctx, childSpan = tracer.Start(ctx, "child") ctx, childSpan = tracer.Start(ctx, "child")
defer childSpan.End() defer childSpan.End()
// do work here, when this function returns, childSpan will complete. // do work here, when this function returns, childSpan will complete.
} }
``` ```