Skip to content

Commit

Permalink
Merge pull request #45 from go-faster/feat/otel-instrumentation
Browse files Browse the repository at this point in the history
feat: add otel instrumentation to Ping
  • Loading branch information
ernado authored Feb 14, 2022
2 parents c504021 + aff7759 commit ce4f19a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/compress/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const (
ZSTD Method = 0x90
)

// Constants for compression encoding.
//
// See https://go-faster.org/docs/clickhouse/compression for reference.
const (
checksumSize = 16
compressHeaderSize = 1 + 4 + 4
Expand Down
26 changes: 25 additions & 1 deletion ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,35 @@ import (
"context"

"github.com/go-faster/errors"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"

"github.com/go-faster/ch/otelch"
"github.com/go-faster/ch/proto"
)

func (c *Client) Ping(ctx context.Context) error {
// Ping server.
//
// Do not call concurrently with Query.
func (c *Client) Ping(ctx context.Context) (err error) {
if c.otel {
newCtx, span := c.tracer.Start(ctx, "Ping",
trace.WithSpanKind(trace.SpanKindClient),
trace.WithAttributes(
otelch.ProtocolVersion(c.protocolVersion),
),
)
ctx = newCtx
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "Failed")
} else {
span.SetStatus(codes.Ok, "")
}
span.End()
}()
}
c.buf.Encode(proto.ClientCodePing)
if err := c.flush(ctx); err != nil {
return errors.Wrap(err, "flush")
Expand Down

0 comments on commit ce4f19a

Please sign in to comment.