| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package otelgrpc |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import ( |
| 9 |
"net" |
| 10 |
"strconv" |
| 11 |
|
| 12 |
"go.opentelemetry.io/otel/attribute" |
| 13 |
"go.opentelemetry.io/otel/codes" |
| 14 |
semconv "go.opentelemetry.io/otel/semconv/v1.40.0" |
| 15 |
grpc_codes "google.golang.org/grpc/codes" |
| 16 |
"google.golang.org/grpc/status" |
| 17 |
) |
| 18 |
|
| 19 |
|
| 20 |
func serverAddrAttrs(hostport string) []attribute.KeyValue { |
| 21 |
h, pStr, err := net.SplitHostPort(hostport) |
| 22 |
if err != nil { |
| 23 |
|
| 24 |
return []attribute.KeyValue{semconv.ServerAddress(hostport)} |
| 25 |
} |
| 26 |
p, err := strconv.Atoi(pStr) |
| 27 |
if err != nil { |
| 28 |
return []attribute.KeyValue{semconv.ServerAddress(h)} |
| 29 |
} |
| 30 |
return []attribute.KeyValue{ |
| 31 |
semconv.ServerAddress(h), |
| 32 |
semconv.ServerPort(p), |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
func serverStatus(grpcStatus *status.Status) (codes.Code, string) { |
| 46 |
switch grpcStatus.Code() { |
| 47 |
case grpc_codes.Unknown, |
| 48 |
grpc_codes.DeadlineExceeded, |
| 49 |
grpc_codes.Unimplemented, |
| 50 |
grpc_codes.Internal, |
| 51 |
grpc_codes.Unavailable, |
| 52 |
grpc_codes.DataLoss: |
| 53 |
return codes.Error, grpcStatus.Message() |
| 54 |
default: |
| 55 |
return codes.Unset, "" |
| 56 |
} |
| 57 |
} |