Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Replace OpenCensus with OpenTelemetry #2136

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions cmd/containerd-shim-runhcs-v1/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/memory"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/otelutil"
"github.com/Microsoft/hcsshim/internal/winapi"
)

Expand Down Expand Up @@ -57,9 +57,9 @@ The delete command will be executed in the container's bundle as its cwd.
// task.DeleteResponse by protocol. We can write to stderr which will be
// logged as a warning in containerd.

ctx, span := oc.StartSpan(context.Background(), "delete")
ctx, span := otelutil.StartSpan(context.Background(), "delete")
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
defer func() { otelutil.SetSpanStatus(span, err) }()

bundleFlag := cCtx.GlobalString("bundle")
if bundleFlag == "" {
Expand Down
14 changes: 7 additions & 7 deletions cmd/containerd-shim-runhcs-v1/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"context"
"fmt"

"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/otelutil"
"github.com/containerd/containerd/namespaces"
shim "github.com/containerd/containerd/runtime/v2/shim"
"go.opencensus.io/trace"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

type publisher interface {
Expand Down Expand Up @@ -39,12 +40,11 @@ func (e *eventPublisher) close() error {
}

func (e *eventPublisher) publishEvent(ctx context.Context, topic string, event interface{}) (err error) {
ctx, span := oc.StartSpan(ctx, "publishEvent")
ctx, span := otelutil.StartSpan(ctx, "publishEvent", trace.WithAttributes(
attribute.String("topic", topic),
attribute.String("event", fmt.Sprintf("%+v", event))))
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(
trace.StringAttribute("topic", topic),
trace.StringAttribute("event", fmt.Sprintf("%+v", event)))
defer func() { otelutil.SetSpanStatus(span, err) }()

if e == nil {
return nil
Expand Down
21 changes: 10 additions & 11 deletions cmd/containerd-shim-runhcs-v1/exec_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/Microsoft/hcsshim/internal/cmd"
"github.com/Microsoft/hcsshim/internal/cow"
"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/otelutil"
"github.com/Microsoft/hcsshim/internal/protocol/guestresource"
"github.com/Microsoft/hcsshim/internal/signals"
"github.com/Microsoft/hcsshim/internal/uvm"
Expand Down Expand Up @@ -448,12 +449,11 @@ func (he *hcsExec) exitFromCreatedL(ctx context.Context, status int) {
// `Create`/`Wait`/`Start` which is a valid pattern.
func (he *hcsExec) waitForExit() {
var err error // this will only save the last error, since we dont return early on error
ctx, span := oc.StartSpan(context.Background(), "hcsExec::waitForExit")
ctx, span := otelutil.StartSpan(context.Background(), "hcsExec::waitForExit", trace.WithAttributes(
attribute.String("tid", he.tid),
attribute.String("eid", he.id)))
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(
trace.StringAttribute("tid", he.tid),
trace.StringAttribute("eid", he.id))
defer func() { otelutil.SetSpanStatus(span, err) }()

err = he.p.Process.Wait()
if err != nil {
Expand Down Expand Up @@ -511,11 +511,10 @@ func (he *hcsExec) waitForExit() {
//
// This MUST be called via a goroutine at exec create.
func (he *hcsExec) waitForContainerExit() {
ctx, span := oc.StartSpan(context.Background(), "hcsExec::waitForContainerExit")
ctx, span := otelutil.StartSpan(context.Background(), "hcsExec::waitForContainerExit", trace.WithAttributes(
attribute.String("tid", he.tid),
attribute.String("eid", he.id)))
defer span.End()
span.AddAttributes(
trace.StringAttribute("tid", he.tid),
trace.StringAttribute("eid", he.id))

// wait for container or process to exit and ckean up resrources
select {
Expand Down
13 changes: 8 additions & 5 deletions cmd/containerd-shim-runhcs-v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"go.opencensus.io/trace"
"go.opentelemetry.io/otel"
sdktrace "go.opentelemetry.io/otel/sdk/trace"

"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/otelutil"
"github.com/Microsoft/hcsshim/internal/shimdiag"
hcsversion "github.com/Microsoft/hcsshim/internal/version"

Expand Down Expand Up @@ -102,9 +103,11 @@ func main() {
),
)

// Register our OpenCensus logrus exporter
trace.ApplyConfig(trace.Config{DefaultSampler: oc.DefaultSampler})
trace.RegisterExporter(&oc.LogrusExporter{})
// Register our OTel logrus exporter
otel.SetTracerProvider(sdktrace.NewTracerProvider(
sdktrace.WithSampler(otelutil.DefaultSampler),
sdktrace.WithBatcher(&otelutil.LogrusExporter{}),
))

app := cli.NewApp()
app.Name = "containerd-shim-runhcs-v1"
Expand Down
4 changes: 2 additions & 2 deletions cmd/containerd-shim-runhcs-v1/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/Microsoft/hcsshim/internal/extendedtask"
hcslog "github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/shimdiag"
"github.com/Microsoft/hcsshim/pkg/octtrpc"
"github.com/Microsoft/hcsshim/pkg/otelttrpc"
)

var svc *service
Expand Down Expand Up @@ -193,7 +193,7 @@ var serveCommand = cli.Command{
return fmt.Errorf("failed to create new service: %w", err)
}

s, err := ttrpc.NewServer(ttrpc.WithUnaryServerInterceptor(octtrpc.ServerInterceptor()))
s, err := ttrpc.NewServer(ttrpc.WithUnaryServerInterceptor(otelttrpc.ServerInterceptor()))
if err != nil {
return err
}
Expand Down
Loading