Skip to content

Commit

Permalink
Improved observability
Browse files Browse the repository at this point in the history
  • Loading branch information
bcessa committed Aug 12, 2022
1 parent 0e72985 commit 31073ae
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jobs:
- name: Static analysis
uses: golangci/golangci-lint-action@v3.2.0
with:
version: v1.47.3
version: v1.48.0

# Run unit tests
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.18.x

# Checkout code
- name: Checkout repository
Expand Down
13 changes: 7 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ nfpms:
vendor: Algorand Foundation
homepage: https://github.com/algorandfoundation/did-algo
maintainer: Ben Cessa <ben@aid.technology>
description: Dencentralized Identifiers for the Algorand blockchain
description: Decentralized Identifiers for the Algorand blockchain
license: BSD-3-Clause
formats:
# Alpine
Expand All @@ -131,22 +131,23 @@ nfpms:
- rpm
# Binary location
bindir: /usr/local/bin
# Folders created and managed by the installer
empty_folders:
- /etc/algoid
# Additional files managed by the installer
contents:
- src: sample-config.yaml
dst: /etc/algoid/config.yaml
type: "config|noreplace"
changelog:
# Sorts the changelog commit messages (asc, desc or '')
sort: ''
# Remove certain commit messages from the changelog
filters:
# Standard commit messages can help to produce better changelogs
# https://www.conventionalcommits.org/en/v1.0.0/
exclude:
- "^docs:"
- "^test:"
- "^chore:"
- typo
- "^typo:"
# Produce homebrew formulas for the project artifacts
# https://goreleaser.com/customization/homebrew/
brews:
Expand All @@ -167,7 +168,7 @@ brews:
# Project details
homepage: "https://github.com/algorandfoundation/did-algo"
description: |
Reference client implementation for the 'bryk' DID method. The platform allows
Reference client implementation for the 'algo' DID method. The platform allows
entities to fully manage Decentralized Identifiers as described on the version
v1.0 of the specification.
install: |
Expand Down
36 changes: 2 additions & 34 deletions agent/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
protoV1 "github.com/algorandfoundation/did-algo/proto/did/v1"
"go.bryk.io/pkg/otel"
otelcodes "go.opentelemetry.io/otel/codes"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
)
Expand All @@ -20,21 +18,10 @@ type rpcHandler struct {
handler *Handler
}

func getHeaders() metadata.MD {
return metadata.New(map[string]string{
"x-content-type-options": "nosniff",
})
}

func (rh *rpcHandler) Ping(ctx context.Context, _ *emptypb.Empty) (*protoV1.PingResponse, error) {
// Track operation
sp := rh.handler.oop.Start(ctx, "Ping", otel.WithSpanKind(otel.SpanKindServer))
defer sp.End()

if err := grpc.SendHeader(ctx, getHeaders()); err != nil {
sp.SetStatus(otelcodes.Error, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return &protoV1.PingResponse{Ok: true}, nil
}

Expand All @@ -43,11 +30,7 @@ func (rh *rpcHandler) Process(ctx context.Context, req *protoV1.ProcessRequest)
sp := rh.handler.oop.Start(ctx, "Process", otel.WithSpanKind(otel.SpanKindServer))
defer sp.End()

if err := grpc.SendHeader(ctx, getHeaders()); err != nil {
sp.SetStatus(otelcodes.Error, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}

// Process and return response
cid, err := rh.handler.Process(req)
if err != nil {
sp.SetStatus(otelcodes.Error, err.Error())
Expand All @@ -64,10 +47,7 @@ func (rh *rpcHandler) Query(ctx context.Context, req *protoV1.QueryRequest) (*pr
sp := rh.handler.oop.Start(ctx, "Query", otel.WithSpanKind(otel.SpanKindServer))
defer sp.End()

if err := grpc.SendHeader(ctx, getHeaders()); err != nil {
sp.SetStatus(otelcodes.Error, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
// Process and return response
id, proof, err := rh.handler.Retrieve(req)
if err != nil {
sp.SetStatus(otelcodes.Error, err.Error())
Expand All @@ -87,21 +67,13 @@ func (rh *rpcHandler) TxParameters(ctx context.Context, _ *emptypb.Empty) (*prot
// Track operation
sp := rh.handler.oop.Start(ctx, "TxParameters", otel.WithSpanKind(otel.SpanKindServer))
defer sp.End()
if err := grpc.SendHeader(ctx, getHeaders()); err != nil {
sp.SetStatus(otelcodes.Error, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return rh.handler.TxParameters(ctx)
}

func (rh *rpcHandler) TxSubmit(ctx context.Context, req *protoV1.TxSubmitRequest) (*protoV1.TxSubmitResponse, error) {
// Track operation
sp := rh.handler.oop.Start(ctx, "TxSubmit", otel.WithSpanKind(otel.SpanKindServer))
defer sp.End()
if err := grpc.SendHeader(ctx, getHeaders()); err != nil {
sp.SetStatus(otelcodes.Error, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return rh.handler.TxSubmit(ctx, req)
}

Expand All @@ -111,10 +83,6 @@ func (rh *rpcHandler) AccountInformation(
// Track operation
sp := rh.handler.oop.Start(ctx, "AccountInformation", otel.WithSpanKind(otel.SpanKindServer))
defer sp.End()
if err := grpc.SendHeader(ctx, getHeaders()); err != nil {
sp.SetStatus(otelcodes.Error, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return rh.handler.AccountInformation(ctx, req)
}

Expand Down

0 comments on commit 31073ae

Please sign in to comment.