Skip to content

Commit 57e8bb7

Browse files
committed
feat(otel): integrate OTEL using gRPC interceptor (#223)
Because - Opentelemetry stack requires the application instrumented in observable layers and components. We desire to have Instill Core a middleware/interceptor approach so functions in handler, service and repository layer can be instrumented automatically. This commit - builds the ground of the instrument which enable handler OTEL tracing interceptor using the latest `x/otel`, `x/errors` and `x/log` package - makes naming consistent
1 parent fa26ce0 commit 57e8bb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+710
-1419
lines changed

.github/CONTRIBUTING.md

Lines changed: 0 additions & 110 deletions
This file was deleted.

Dockerfile.dev

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ARG GOLANG_VERSION=1.24.4
22
FROM golang:${GOLANG_VERSION}-bullseye
33

4-
ARG SERVICE_NAME
4+
ARG SERVICE_NAME SERVICE_VERSION
55

66
WORKDIR /${SERVICE_NAME}
77

@@ -29,6 +29,9 @@ RUN chown -R nobody:nogroup /go
2929
ENV GOCACHE=/go/.cache/go-build
3030
ENV GOENV=/go/.config/go/env
3131

32+
ENV SERVICE_NAME=${SERVICE_NAME}
33+
ENV SERVICE_VERSION=${SERVICE_VERSION}
34+
3235
USER nobody:nogroup
3336

3437
ENTRYPOINT ["tail", "-f", "/dev/null"]

cmd/init/main.go

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,57 @@ package main
22

33
import (
44
"context"
5-
"fmt"
5+
"log"
66
"time"
77

88
"go.uber.org/zap"
99
"google.golang.org/grpc/metadata"
1010

11+
grpczap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
12+
1113
"github.com/instill-ai/artifact-backend/config"
1214
"github.com/instill-ai/artifact-backend/pkg/service"
13-
"github.com/instill-ai/x/log"
1415

15-
grpcclient "github.com/instill-ai/artifact-backend/pkg/client/grpc"
1616
pipelinepb "github.com/instill-ai/protogen-go/pipeline/pipeline/v1beta"
17+
clientx "github.com/instill-ai/x/client"
18+
clientgrpcx "github.com/instill-ai/x/client/grpc"
19+
logx "github.com/instill-ai/x/log"
1720
)
1821

1922
func main() {
2023
ctx := context.Background()
2124

22-
log.Debug = config.Config.Server.Debug
23-
logger, _ := log.GetZapLogger(ctx)
25+
if err := config.Init(config.ParseConfigFlag()); err != nil {
26+
log.Fatal(err.Error())
27+
}
28+
29+
logx.Debug = config.Config.Server.Debug
30+
logger, _ := logx.GetZapLogger(context.Background())
31+
defer func() {
32+
// can't handle the error due to https://github.com/uber-go/zap/issues/880
33+
_ = logger.Sync()
34+
}()
2435

25-
if err := config.Init(); err != nil {
26-
logger.Fatal("Failed to initialize config", zap.Error(err))
36+
// Set gRPC logging based on debug mode
37+
if config.Config.Server.Debug {
38+
grpczap.ReplaceGrpcLoggerV2WithVerbosity(logger, 0) // All logs
39+
} else {
40+
grpczap.ReplaceGrpcLoggerV2WithVerbosity(logger, 3) // verbosity 3 will avoid [transport] from emitting
2741
}
2842

29-
pipelinePublicGrpcConn, err := grpcclient.NewGRPCConn(
30-
fmt.Sprintf("%v:%v", config.Config.PipelineBackend.Host,
31-
config.Config.PipelineBackend.PublicPort),
32-
config.Config.PipelineBackend.HTTPS.Cert,
33-
config.Config.PipelineBackend.HTTPS.Key)
43+
pipelinePublicServiceClient, pipelinePublicClose, err := clientgrpcx.NewClient[pipelinepb.PipelinePublicServiceClient](
44+
clientgrpcx.WithServiceConfig(clientx.ServiceConfig{
45+
Host: config.Config.PipelineBackend.Host,
46+
PublicPort: config.Config.PipelineBackend.PublicPort,
47+
}),
48+
clientgrpcx.WithSetOTELClientHandler(config.Config.OTELCollector.Enable),
49+
)
3450
if err != nil {
35-
logger.Fatal("Failed to create pipeline client", zap.Error(err))
51+
logger.Fatal("failed to create pipeline public service client", zap.Error(err))
3652
}
3753
defer func() {
38-
if err := pipelinePublicGrpcConn.Close(); err != nil {
39-
logger.Error("Failed to close pipeline client", zap.Error(err))
54+
if err := pipelinePublicClose(); err != nil {
55+
logger.Error("failed to close pipeline public service client", zap.Error(err))
4056
}
4157
}()
4258

@@ -46,7 +62,7 @@ func main() {
4662

4763
upserter := &service.PipelineReleaseUpserter{
4864
FS: service.PresetPipelinesFS,
49-
PipelinePublicServiceClient: pipelinepb.NewPipelinePublicServiceClient(pipelinePublicGrpcConn),
65+
PipelinePublicServiceClient: pipelinePublicServiceClient,
5066
}
5167

5268
for _, pr := range service.PresetPipelinesList {

0 commit comments

Comments
 (0)