traceid

package module
v0.0.0-...-5c29987 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 9 Imported by: 0

README

TraceID Setting Plugin

Returning the trace ID of the call chain during interface debugging can improve problem troubleshooting efficiency.

  • It can be used as a tRPC-Go filter by configuring it in trpc_go.yaml.
  • It can also be used as a gateway plugin, configured to be effective at the interface level.

img.png

Note: Only sampled requests will return the trace ID.

Usage

Import the Plugin in the main.go of the Gateway Project
  • Add the import statement:
import (
    _ "trpc.group/trpc-go/trpc-gateway/plugin/traceid"
)
  • Configure the tRPC framework in the configuration file to enable the trace ID interceptor.

Note: Make sure to register it in server.service.filter, not server.filter.

global:                             # Global configuration
server:                             # Server configuration
  filter:                          # Interceptor list for all service handler functions
  service:                          # Business services provided, can have multiple
    - name: trpc.inews.trpc.gateway      # Route name of the service
      filter:
        - traceid # Gateway plugin registered in the service filter, so that it can be dynamically loaded in router.yaml
plugins:                            # Plugin configuration
  log:                              # Log configuration
  gateway:                          # Plugin type is gateway
    traceid:                        # TraceID plugin
Configure the Plugin in the Gateway Router Configuration router.yaml File
router:                             # Router configuration
  - method: /v1/user/info
    id: "xxxxxx"
    target_service:
      - service: trpc.user.service
    plugins:
      - name: traceid                # Route-level plugin
client:                             # Upstream service configuration, consistent with the tRPC protocol
  - name: trpc.user.service
    plugins:
      - name: traceid                # Service-level configuration
        props:
plugins:
  - name: traceid                    # Global configuration

Documentation

Overview

Package traceid provides trace ID handling

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServerFilter

func ServerFilter(ctx context.Context, req interface{}, handler filter.ServerHandleFunc) (interface{}, error)

ServerFilter is the server-side interceptor

Types

type Options

type Options struct{}

Options is the plugin configuration

type Plugin

type Plugin struct{}

Plugin is the traceid plugin definition

func (*Plugin) CheckConfig

func (p *Plugin) CheckConfig(_ string, decoder plugin.Decoder) error

CheckConfig validates the traceid plugin configuration and returns the parsed configuration object for use in the ServerFilter method

func (*Plugin) Setup

func (p *Plugin) Setup(string, plugin.Decoder) error

Setup initializes the traceid plugin

func (*Plugin) Type

func (p *Plugin) Type() string

Type returns the traceid plugin type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL