Skip to content

Commit 7a58500

Browse files
committed
Added ServiceInstanceID options to resource
1 parent 5c83fbf commit 7a58500

6 files changed

Lines changed: 11 additions & 7 deletions

File tree

internal/grpcinject/opentelemetry.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"google.golang.org/grpc"
3434
)
3535

36-
func OpenTelemetry(config *config.Config, localAddr net.Addr, publicAddr string) error {
36+
func OpenTelemetry(config *config.Config, instanceID string, localAddr net.Addr, publicAddr string) error {
3737
resOptions := []resource.Option{
3838
resource.WithHost(),
3939
resource.WithOS(),
@@ -42,6 +42,7 @@ func OpenTelemetry(config *config.Config, localAddr net.Addr, publicAddr string)
4242
resource.WithTelemetrySDK(),
4343
resource.WithSchemaURL(semconv.SchemaURL),
4444
resource.WithAttributes(semconv.ServiceName(config.OpenTelemetry.ServiceName)),
45+
resource.WithAttributes(semconv.ServiceInstanceID(instanceID)),
4546
}
4647

4748
if localAddr != nil {

rpcplatform_grpcinject.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
"github.com/nexcode/rpcplatform/internal/grpcinject"
2323
)
2424

25-
func (p *RPCPlatform) grpcinject(localAddr net.Addr, publicAddr string) error {
25+
func (p *RPCPlatform) grpcinject(instanceID string, localAddr net.Addr, publicAddr string) error {
2626
if p.config.OpenTelemetry != nil {
27-
if err := grpcinject.OpenTelemetry(p.config, localAddr, publicAddr); err != nil {
27+
if err := grpcinject.OpenTelemetry(p.config, instanceID, localAddr, publicAddr); err != nil {
2828
return err
2929
}
3030
}

rpcplatform_newclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (p *RPCPlatform) NewClient(target string, attributes *ClientAttributes) (*C
4040
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig":[{"`+balancerName+`":{}}]}`),
4141
)
4242

43-
if err := p.grpcinject(nil, ""); err != nil {
43+
if err := p.grpcinject(gears.UID(), nil, ""); err != nil {
4444
return nil, err
4545
}
4646

rpcplatform_newserver.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ func (p *RPCPlatform) NewServer(name, addr string, attributes *ServerAttributes,
4242
addr = listener.Addr().String()
4343
}
4444

45-
if err = p.grpcinject(listener.Addr(), addr); err != nil {
45+
id := gears.UID()
46+
47+
if err = p.grpcinject(id, listener.Addr(), addr); err != nil {
4648
return nil, err
4749
}
4850

4951
return &Server{
52+
id: id,
5053
name: p.config.EtcdPrefix + gears.FixPath(name),
5154
etcd: p.config.EtcdClient,
5255
server: grpc.NewServer(p.config.GRPCOptions.Server...),

server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
)
2525

2626
type Server struct {
27+
id string
2728
name string
2829
etcd *etcd.Client
2930
server *grpc.Server

server_serve.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"time"
2323

24-
"github.com/nexcode/rpcplatform/internal/gears"
2524
etcd "go.etcd.io/etcd/client/v3"
2625
)
2726

@@ -36,7 +35,7 @@ func (s *Server) Serve() error {
3635
}()
3736

3837
go func() {
39-
path := s.name + "/" + gears.UID()
38+
path := s.name + "/" + s.id
4039

4140
for {
4241
if !serving {

0 commit comments

Comments
 (0)