generated from cloudwego/.github
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Organize the observability components of Cloudwego (#2)
* combine logging for kitex and hertz * combine logging for kitex and hertz V2 * combine logging for kitex and hertz V2 * combine metrics * otel V2 * logging down * logging V2 * propagtor V1 * propagtor V2 * fix * 可观测组件整合 V2 * 抽象otel和promth共性逻辑 * 抽象otel和promth共性逻辑 update * fix bug * fix Reference Path * add promProvider * add labelControl * fix bugs * fix format * fix CI * fix labelControl name, fix promProvider,promTracer * fix labelControl name, fix promProvider,promTracer * move Measure build to promProvider * Unified Label Standard * fix CI * fix CI bugs * fix CI bugs * fix CI bug * fix remove registry from tracer * fix CI gofumpt * fix change name to telemetry * fix remove promtracer * fix tracer * fix file_name * remove labelcontrol * Standardized code * add recorder for retry * update test * fix Data Race * fix Data Race * remove promProvider test add example * fix format * move go.mod to telemetry * update makefile * update makefile, update file name * update makefile,update labels * update measure structure * update measure structure * update formate * update TelemetryProvider * update Code Formatting * update build name func * Optimize logical structure * Support simultaneous monitoring of HTTP and RPC * remove measure form promProvider * update labels * otel log component compatible with Kitex * fix path * replace logging to hlog * Replace logging with hlog * fix * fix * fix log && Optimize promProvider * update example for promProvider * update go work and fix CI * fix log * Fix duplicate naming for prometheus * fix ci * update server * update to metadata, support shell * update CI * add examples and support shell * fix bugs remove the Local dependencies * fix CI * fix CI * fix ci & add counter to otelkitex * fix unit test ci * fix unit test ci * fix unit test ci
- Loading branch information
1 parent
2a76522
commit 80a98db
Showing
129 changed files
with
11,681 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
TOOLS_SHELL="./hack/tools.sh" | ||
|
||
.PHONY: test | ||
test: | ||
chmod +x ${TOOLS_SHELL} | ||
@${TOOLS_SHELL} test | ||
@echo "go test finished" | ||
|
||
|
||
|
||
.PHONY: vet | ||
vet: | ||
chmod +x ${TOOLS_SHELL} | ||
@${TOOLS_SHELL} vet | ||
@echo "vet check finished" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2024 CloudWeGo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
func main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 CloudWeGo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/cloudwego-contrib/cwgo-pkg/telemetry/instrumentation/otelhertz" | ||
"github.com/cloudwego-contrib/cwgo-pkg/telemetry/provider/otelprovider" | ||
"github.com/cloudwego/hertz/pkg/app/client" | ||
"github.com/cloudwego/hertz/pkg/common/hlog" | ||
hertzlogrus "github.com/hertz-contrib/obs-opentelemetry/logging/logrus" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
) | ||
|
||
func main() { | ||
hlog.SetLogger(hertzlogrus.NewLogger()) | ||
hlog.SetLevel(hlog.LevelDebug) | ||
|
||
serviceName := "demo-hertz-client" | ||
|
||
p := otelprovider.NewOpenTelemetryProvider( | ||
otelprovider.WithServiceName(serviceName), | ||
// Support setting ExportEndpoint via environment variables: OTEL_EXPORTER_OTLP_ENDPOINT | ||
otelprovider.WithExportEndpoint("localhost:4317"), | ||
otelprovider.WithHttpServer(), | ||
otelprovider.WithInsecure(), | ||
) | ||
defer p.Shutdown(context.Background()) | ||
|
||
c, _ := client.NewClient() | ||
c.Use(otelhertz.ClientMiddleware()) | ||
|
||
for { | ||
ctx, span := otel.Tracer("github.com/hertz-contrib/obs-opentelemetry"). | ||
Start(context.Background(), "loop") | ||
|
||
_, b, err := c.Get(ctx, nil, "http://0.0.0.0:8888/ping?foo=bar") | ||
if err != nil { | ||
hlog.CtxErrorf(ctx, err.Error()) | ||
} | ||
|
||
span.SetAttributes(attribute.String("msg", string(b))) | ||
|
||
hlog.CtxInfof(ctx, "hertz client %s", string(b)) | ||
span.End() | ||
|
||
<-time.After(time.Second) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module otelwithhertz | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/cloudwego/hertz v0.9.3 | ||
github.com/hertz-contrib/obs-opentelemetry/logging/logrus v0.1.1 | ||
) | ||
|
||
require ( | ||
github.com/sirupsen/logrus v1.8.1 // indirect | ||
go.opentelemetry.io/otel v1.4.1 // indirect | ||
go.opentelemetry.io/otel/trace v1.4.1 // indirect | ||
golang.org/x/sys v0.24.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2024 CloudWeGo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"exampleprom/promWithkitex/kitex_gen/api" | ||
|
||
"github.com/cloudwego-contrib/cwgo-pkg/telemetry/instrumentation/otelhertz" | ||
"github.com/cloudwego-contrib/cwgo-pkg/telemetry/provider/otelprovider" | ||
"github.com/cloudwego/hertz/pkg/app" | ||
"github.com/cloudwego/hertz/pkg/app/server" | ||
"github.com/cloudwego/hertz/pkg/common/hlog" | ||
"github.com/cloudwego/hertz/pkg/protocol/consts" | ||
hertzlogrus "github.com/hertz-contrib/obs-opentelemetry/logging/logrus" | ||
) | ||
|
||
func main() { | ||
hlog.SetLogger(hertzlogrus.NewLogger()) | ||
hlog.SetLevel(hlog.LevelDebug) | ||
|
||
serviceName := "demo-hertz-server" | ||
p := otelprovider.NewOpenTelemetryProvider( | ||
otelprovider.WithServiceName(serviceName), | ||
// Support setting ExportEndpoint via environment variables: OTEL_EXPORTER_OTLP_ENDPOINT | ||
otelprovider.WithExportEndpoint("localhost:4317"), | ||
otelprovider.WithHttpServer(), | ||
otelprovider.WithInsecure(), | ||
) | ||
defer p.Shutdown(context.Background()) | ||
|
||
tracer, cfg := otelhertz.NewServerOption() | ||
h := server.Default(tracer) | ||
h.Use(otelhertz.ServerMiddleware(cfg)) | ||
|
||
h.GET("/ping", func(c context.Context, ctx *app.RequestContext) { | ||
req := &api.Request{Message: "my request"} | ||
|
||
hlog.CtxDebugf(c, "message received successfully: %s", req.Message) | ||
ctx.JSON(consts.StatusOK, "resp") | ||
}) | ||
|
||
h.Spin() | ||
} |
Oops, something went wrong.