Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feature: make trace with jaeger & opentelemetry #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Fleezesd
Copy link

  • Use opentelemetry as the traceprovider for link tracking, but I hope to reduce the intrusion of the business code, so I chose the otelgin official middleware method to directly pass the trace information to jaeger. It depends on the author's choice.
  • And the gateway code returns 200 business status code for rpc service errors. See if the error codes need to be unified like kratos framework later.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the binary files

@@ -33,7 +33,7 @@ redis:
redisNetwork: "tcp"

etcd:
address: 127.0.0.1:2380
address: 127.0.0.1:2379
Copy link
Owner

@CocaineCong CocaineCong Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't change this etcd address. the 2380 of etcd is for micro service, and the 2379 of etcd is for milvus.

@@ -15,20 +15,20 @@ func ListFavorite(ctx *gin.Context) {
var req pb.FavoriteListReq
if err := ctx.Bind(&req); err != nil {
log.LogrusObj.Errorf("Bind:%v", err)
ctx.JSON(http.StatusOK, ctl.RespError(ctx, err, "绑定参数错误"))
ctx.JSON(http.StatusInternalServerError, ctl.RespError(ctx, err, "绑定参数错误"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't change this http.StatusOK to http.StatusInternalServerError , we all set the HTTP response code is 200, and we will set the logic of response code in response body, you can see the ctl.RespError()

"fmt"
"github.com/CocaineCong/tangseng/pkg/trace"
"net/http"
Copy link
Owner

@CocaineCong CocaineCong Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the golangci-lint run to standardize the sort of pkg import .

- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2380
- ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2380
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
- ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379
- "ALLOW_NONE_AUTHENTICATION=yes"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change this port back to 2380 ?🤣 you can think a little more before modifying the configuration file. 😂

)

// TODO 若是想用x-request-id 方式连通链路, 也可看middleware下的trace, 按需求来选, 推荐官方的open-telemetry的方式 因jaeger-client已被舍弃
var (
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job!! 👏

@@ -36,7 +41,7 @@ func NewMapReduceServiceClient(cc grpc.ClientConnInterface) MapReduceServiceClie

func (c *mapReduceServiceClient) MasterAssignTask(ctx context.Context, in *MapReduceTask, opts ...grpc.CallOption) (*MapReduceTask, error) {
out := new(MapReduceTask)
err := c.cc.Invoke(ctx, "/MapReduceService/MasterAssignTask", in, out, opts...)
err := c.cc.Invoke(ctx, MapReduceService_MasterAssignTask_FullMethodName, in, out, opts...)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested these files yet? so many change🙂

)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))

return exporter.Shutdown
Copy link
Owner

@CocaineCong CocaineCong Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested trace ? I think this should be appeared in the response body.
such as :

{
    "status": 200,
    "msg": "success",
    "errors": null,
    "data": {},
    "timestamp": 1682042879,
    "trace_id": "0a98685f6441efffb72d687be99381aa"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants