Skip to content

Commit

Permalink
docs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kapv89 committed Nov 23, 2022
1 parent c8c0733 commit 41431dd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
22 changes: 11 additions & 11 deletions go/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ Users are given control over what tags they want to append by using `core.Commen

```go
type CommenterConfig struct {
EnableDBDriver bool
EnableRoute bool
EnableFramework bool
EnableController bool
EnableAction bool
EnableTraceparent bool
EnableApplication bool
EnableDBDriver bool
EnableRoute bool
EnableFramework bool
EnableController bool
EnableAction bool
EnableTraceparent bool
EnableApplication bool
}
```

Users can also set the values for some static tags by using `core.StaticTags` struct.

```go
type StaticTags struct {
Application string
DriverName string
Application string
DriverName string
}
```

These two structs together form the `core.CommenterOptions` struct, which is used by [sqlcommenter/go/database/sql](../database/sql/README.md).

```go
type CommenterOptions struct {
Config CommenterConfig
Tags StaticTags
Config CommenterConfig
Tags StaticTags
}
```
30 changes: 15 additions & 15 deletions go/database/sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Due to inherent nature of Go, the safer way to pass information from framework t

```go
import (
gosql "github.com/google/sqlcommenter/go/database/sql"
sqlcommentercore "github.com/google/sqlcommenter/go/core"
_ "github.com/lib/pq" // or any other database driver
gosql "github.com/google/sqlcommenter/go/database/sql"
sqlcommentercore "github.com/google/sqlcommenter/go/core"
_ "github.com/lib/pq" // or any other database driver
)

db, err := gosql.Open("<driver>", "<connectionString>", sqlcommentercore.CommenterOptions{
Config: sqlcommentercore.CommenterConfig{<flag>:bool}
Tags : sqlcommentercore.StaticTags{<tag>: string} // optional
Config: sqlcommentercore.CommenterConfig{<flag>:bool}
Tags : sqlcommentercore.StaticTags{<tag>: string} // optional
})
```

Expand All @@ -32,22 +32,22 @@ Users are given control over what tags they want to append by using `core.Commen

```go
type CommenterOptions struct {
EnableDBDriver bool
EnableTraceparent bool // OpenTelemetry trace information
EnableRoute bool // applicable for web frameworks
EnableFramework bool // applicable for web frameworks
EnableController bool // applicable for web frameworks
EnableAction bool // applicable for web frameworks
EnableApplication bool // applicable for web frameworks
EnableDBDriver bool
EnableTraceparent bool // OpenTelemetry trace information
EnableRoute bool // applicable for web frameworks
EnableFramework bool // applicable for web frameworks
EnableController bool // applicable for web frameworks
EnableAction bool // applicable for web frameworks
EnableApplication bool // applicable for web frameworks
}
```

Users can also provide static tags they want to use by using `core.StaticTags` struct. These tags are optional
Users can also provide static tags they want to use by using `core.StaticTags` struct. These tags are optional. If not provided, the `Application` tag will get auto-populated from the user-project's module-name in `go.mod`. `DriverName` is set to the driver-name provided in `gosql.Open(driverName, ...)` call.

```go
type StaticTags struct {
Application string
DriverName string
Application string
DriverName string
}
```

Expand Down
68 changes: 34 additions & 34 deletions go/gorrila/mux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"net/http"

sqlcommentermux "github.com/google/sqlcommenter/go/gorrila/mux"
"github.com/gorilla/mux"
"github.com/gorilla/mux"
)

func runApp() {
r := mux.NewRouter()
r.Use(sqlcommentermux.SQLCommenterMiddleware)
r := mux.NewRouter()
r.Use(sqlcommentermux.SQLCommenterMiddleware)

r.HandleFunc("/", ActionHome).Methods("GET")
r.HandleFunc("/", ActionHome).Methods("GET")

http.ListenAndServe(":8081", r)
}
Expand All @@ -38,49 +38,49 @@ func runApp() {
```go
import (
"context"
"log"
"net/http"
"log"
"net/http"

sqlcommentermux "github.com/google/sqlcommenter/go/gorrila/mux"
"github.com/gorilla/mux"
"go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux"
"go.opentelemetry.io/otel"
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/propagation"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"github.com/gorilla/mux"
"go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux"
"go.opentelemetry.io/otel"
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/propagation"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

func main() {
tp, err := initTracer()
if err != nil {
log.Fatal(err)
}
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
log.Printf("Error shutting down tracer provider: %v", err)
}
}()
if err != nil {
log.Fatal(err)
}
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
log.Printf("Error shutting down tracer provider: %v", err)
}
}()

r := mux.NewRouter()
r.Use(otelmux.Middleware("sqlcommenter sample-server"), sqlcommentermux.SQLCommenterMiddleware)
r := mux.NewRouter()
r.Use(otelmux.Middleware("sqlcommenter sample-server"), sqlcommentermux.SQLCommenterMiddleware)

r.HandleFunc("/", ActionHome).Methods("GET")
r.HandleFunc("/", ActionHome).Methods("GET")

http.ListenAndServe(":8081", r)
}

func initTracer() (*sdktrace.TracerProvider, error) {
exporter, err := stdout.New(stdout.WithPrettyPrint())
if err != nil {
return nil, err
}
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithBatcher(exporter),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
return tp, nil
exporter, err := stdout.New(stdout.WithPrettyPrint())
if err != nil {
return nil, err
}
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithBatcher(exporter),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
return tp, nil
}
```

Expand Down
2 changes: 1 addition & 1 deletion go/net/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This is a low-level package that can be used to prepare SQLCommeneterTags out of

```go
import (
sqlcommenterhttp "github.com/google/sqlcommenter/go/net/http"
sqlcommenterhttp "github.com/google/sqlcommenter/go/net/http"
)

requestTags := sqlcommenterhttp.NewHTTPRequestTags(framework string, route string, action string)
Expand Down

0 comments on commit 41431dd

Please sign in to comment.