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

feat: Add open telemetry metrics and traces #3404

Merged
merged 21 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ jobs:
coverage-artifact-name: "coverage_encryption"
coverage-path: coverage.txt

# This job runs the database with telemetry tests using default configuration, on linux.
test-telemetry:
name: Test telemetry job

runs-on: ubuntu-latest

env:
GOFLAGS: -tags=telemetry

steps:
- name: Checkout code into the directory
uses: actions/checkout@v4

- name: Setup defradb
uses: ./.github/composites/setup-defradb

- name: Test coverage & save coverage report in an artifact
uses: ./.github/composites/test-coverage-with-artifact
with:
coverage-artifact-name: "coverage_telemetry"
coverage-path: coverage.txt

## This job gathers all the coverage reports and uploads them to code-cov
upload-coverage:
Expand All @@ -248,6 +269,7 @@ jobs:
- test-lens # 2 test(s)
- test-view # 1 test(s)
- test-encryption # 1 test(s)
- test-telemetry # 1 test(s)

# Important to know:
# - We didn't use `if: always()` here, so this job doesn't run if we manually canceled.
Expand Down
2 changes: 2 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var configFlags = map[string]string{
"source-hub-address": "acp.sourceHub.address",
"development": "development",
"secret-file": "secretfile",
"no-telemetry": "telemetry.disabled",
}

// configDefaults contains default values for config entries.
Expand Down Expand Up @@ -96,6 +97,7 @@ var configDefaults = map[string]any{
"log.source": false,
"log.stacktrace": false,
"secretfile": ".env",
"telemetry.disabled": false,
}

// defaultConfig returns a new config with default values.
Expand Down
1 change: 1 addition & 0 deletions cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ func TestLoadConfigNotExist(t *testing.T) {
assert.Equal(t, "file", cfg.GetString("keyring.backend"))

assert.Equal(t, false, cfg.GetBool("development"))
assert.Equal(t, false, cfg.GetBool("telemetry.disabled"))
}
18 changes: 18 additions & 0 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
"github.com/sourcenetwork/defradb/event"
"github.com/sourcenetwork/defradb/http"
"github.com/sourcenetwork/defradb/internal/db"
"github.com/sourcenetwork/defradb/internal/metric"
"github.com/sourcenetwork/defradb/keyring"
"github.com/sourcenetwork/defradb/net"
"github.com/sourcenetwork/defradb/node"
"github.com/sourcenetwork/defradb/version"
)

const devModeBanner = `
Expand Down Expand Up @@ -149,6 +151,17 @@
}
}

if !cfg.GetBool("no-telemetry") {
ver, err := version.NewDefraVersion()
if err != nil {
return err
}
err = metric.ConfigureTelemetry(cmd.Context(), ver.String())
if err != nil {
log.ErrorContextE(cmd.Context(), "failed to configure telemetry", err)
}

Check warning on line 162 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L154-L162

Added lines #L154 - L162 were not covered by tests
}

signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)

Expand Down Expand Up @@ -250,6 +263,11 @@
"no-encryption",
cfg.GetBool(configFlags["no-encryption"]),
"Skip generating an encryption key. Encryption at rest will be disabled. WARNING: This cannot be undone.")
cmd.PersistentFlags().Bool(
"no-telemetry",
cfg.GetBool(configFlags["no-telemetry"]),
"Disables telemetry reporting. Telemetry is only enabled in builds that use the telemetry flag.",
)
return cmd
}

Expand Down
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,7 @@ SourceHub ACP requests in order to create protected data.
## `secretfile`

Path to the file containing secrets. Defaults to `.env`.

## `telemetry.disabled`

Disables telemetry reporting. Telemetry is only enabled in builds that use the `telemetry` flag. Defaults to `false`.
1 change: 1 addition & 0 deletions docs/website/references/cli/defradb_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defradb start [flags]
--max-txn-retries int Specify the maximum number of retries per transaction (default 5)
--no-encryption Skip generating an encryption key. Encryption at rest will be disabled. WARNING: This cannot be undone.
--no-p2p Disable the peer-to-peer network synchronization system
--no-telemetry Disables telemetry reporting. Telemetry is only enabled in builds that use the telemetry flag.
--p2paddr strings Listen addresses for the p2p network (formatted as a libp2p MultiAddr) (default [/ip4/127.0.0.1/tcp/9171])
--peers stringArray List of peers to connect to
--privkeypath string Path to the private key for tls
Expand Down
23 changes: 14 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ require (
github.com/valyala/fastjson v1.6.4
github.com/vito/go-sse v1.1.2
github.com/zalando/go-keyring v0.2.6
go.opentelemetry.io/otel/metric v1.34.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.59.0
go.opentelemetry.io/otel v1.34.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.34.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0
go.opentelemetry.io/otel/sdk v1.34.0
go.opentelemetry.io/otel/sdk/metric v1.34.0
go.opentelemetry.io/otel/trace v1.34.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.32.0
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
Expand Down Expand Up @@ -193,7 +198,7 @@ require (
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down Expand Up @@ -357,15 +362,15 @@ require (
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
go.uber.org/dig v1.18.0 // indirect
go.uber.org/fx v1.23.0 // indirect
go.uber.org/mock v0.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
Expand All @@ -376,9 +381,9 @@ require (
gonum.org/v1/gonum v0.15.0 // indirect
google.golang.org/api v0.171.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
google.golang.org/protobuf v1.36.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/protobuf v1.36.3 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
30 changes: 20 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpg
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 h1:VNqngBF40hVlDloBruUehVYC3ArSgIyScOAyMRqBxRg=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1/go.mod h1:RBRO7fro65R6tjKzYgLAFo0t1QEXY1Dp+i/bvpRiqiQ=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
Expand Down Expand Up @@ -1546,8 +1546,16 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.4
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0/go.mod h1:qxuZLtbq5QDtdeSHsS7bcf6EH6uO6jUAgk764zd3rhM=
go.opentelemetry.io/contrib/instrumentation/runtime v0.59.0 h1:rfi2MMujBc4yowE0iHckZX4o4jg6SA67EnFVL8ldVvU=
go.opentelemetry.io/contrib/instrumentation/runtime v0.59.0/go.mod h1:IO/gfPEcQYpOpPxn1OXFp1DvRY0viP8ONMedXLjjHIU=
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.34.0 h1:opwv08VbCZ8iecIWs+McMdHRcAXzjAeda3uG2kI/hcA=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.34.0/go.mod h1:oOP3ABpW7vFHulLpE8aYtNBodrHhMTrvfxUXGvqm7Ac=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 h1:K0XaT3DwHAcV4nKLzcQvwAgSyisUghWoY20I7huthMk=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0/go.mod h1:B5Ki776z/MBnVha1Nzwp5arlzBbE3+1jk+pGmaP5HME=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 h1:lUsI2TYsQw2r1IASwoROaCnjdj2cvC2+Jbxvk6nHnWU=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0/go.mod h1:2HpZxxQurfGxJlJDblybejHB6RX6pmExPNe517hREw4=
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=
Expand All @@ -1557,6 +1565,8 @@ go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6Yv
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
Expand Down Expand Up @@ -1721,8 +1731,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down Expand Up @@ -2165,10 +2175,10 @@ google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a/go.mod h1:1vXfmgAz
google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71/go.mod h1:9qHF0xnpdSfF6knlcsnpzUu5y+rpwgbvsyGAZPBMg4s=
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY=
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo=
google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a h1:OAiGFfOiA0v9MRYsSidp3ubZaBnteRUyn3xB2ZQ5G/E=
google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a/go.mod h1:jehYqy3+AhJU9ve55aNOaSml7wUXjF9x6z2LcCfpAhY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f h1:gap6+3Gk41EItBuyi4XX/bp4oqJ3UwuIMl25yGinuAA=
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:Ic02D47M+zbarjYYUlK57y316f2MoN0gjAwI3f2S95o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50=
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
Expand Down Expand Up @@ -2231,8 +2241,8 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
8 changes: 4 additions & 4 deletions internal/core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ type SchemaDefinition struct {
// This includes schema and request parsing, and introspection.
type Parser interface {
// BuildRequestAST builds and return AST for the given request.
BuildRequestAST(request string) (*ast.Document, error)
BuildRequestAST(ctx context.Context, request string) (*ast.Document, error)

// Returns true if the given request ast is an introspection request.
IsIntrospection(*ast.Document) bool

// Executes the given introspection request.
ExecuteIntrospection(request string) *client.RequestResult
ExecuteIntrospection(ctx context.Context, request string) *client.RequestResult

// Parses the given request, returning a strongly typed model of that request.
Parse(*ast.Document, *client.GQLOptions) (*request.Request, []error)
Parse(context.Context, *ast.Document, *client.GQLOptions) (*request.Request, []error)

// NewFilterFromString creates a new filter from a string.
NewFilterFromString(collectionType string, body string) (immutable.Option[request.Filter], error)
Expand All @@ -55,7 +55,7 @@ type Parser interface {
// The parsing should validate the syntax, but not validate what that syntax expresses
// is valid or not, i.e. we don't want the parser to make remote calls to verify the
// policy description is valid or not (that is the callers responsiblity).
ParseSDL(sdl string) ([]client.CollectionDefinition, error)
ParseSDL(ctx context.Context, sdl string) ([]client.CollectionDefinition, error)

// Adds the given schema to this parser's model.
//
Expand Down
21 changes: 21 additions & 0 deletions internal/db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@
func (c *collection) GetAllDocIDs(
ctx context.Context,
) (<-chan client.DocIDResult, error) {
ctx, span := tracer.Start(ctx)
defer span.End()

ctx, _, err := ensureContextTxn(ctx, c.db, true)
if err != nil {
return nil, err
Expand Down Expand Up @@ -382,6 +385,9 @@
ctx context.Context,
doc *client.Document,
) error {
ctx, span := tracer.Start(ctx)
defer span.End()

ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return err
Expand All @@ -402,6 +408,9 @@
ctx context.Context,
docs []*client.Document,
) error {
ctx, span := tracer.Start(ctx)
defer span.End()

ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return err
Expand Down Expand Up @@ -485,6 +494,9 @@
ctx context.Context,
doc *client.Document,
) error {
ctx, span := tracer.Start(ctx)
defer span.End()

ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return err
Expand Down Expand Up @@ -546,6 +558,9 @@
ctx context.Context,
doc *client.Document,
) error {
ctx, span := tracer.Start(ctx)
defer span.End()

ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return err
Expand Down Expand Up @@ -841,6 +856,9 @@
ctx context.Context,
docID client.DocID,
) (bool, error) {
ctx, span := tracer.Start(ctx)
defer span.End()

ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return false, err
Expand All @@ -866,6 +884,9 @@
ctx context.Context,
docID client.DocID,
) (bool, error) {
ctx, span := tracer.Start(ctx)
defer span.End()

Check warning on line 889 in internal/db/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/db/collection.go#L887-L889

Added lines #L887 - L889 were not covered by tests
ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return false, err
Expand Down
3 changes: 3 additions & 0 deletions internal/db/collection_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
ctx context.Context,
filter any,
) (*client.DeleteResult, error) {
ctx, span := tracer.Start(ctx)
defer span.End()

Check warning on line 32 in internal/db/collection_delete.go

View check run for this annotation

Codecov / codecov/patch

internal/db/collection_delete.go#L30-L32

Added lines #L30 - L32 were not covered by tests
ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions internal/db/collection_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func (c *collection) Get(
docID client.DocID,
showDeleted bool,
) (*client.Document, error) {
ctx, span := tracer.Start(ctx)
defer span.End()

// create txn
ctx, txn, err := ensureContextTxn(ctx, c.db, true)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions internal/db/collection_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ func (c *collection) CreateIndex(
ctx context.Context,
desc client.IndexDescriptionCreateRequest,
) (client.IndexDescription, error) {
ctx, span := tracer.Start(ctx)
defer span.End()

ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return client.IndexDescription{}, err
Expand Down Expand Up @@ -372,6 +375,9 @@ func (c *collection) indexExistingDocs(
//
// All index artifacts for existing documents related the index will be removed.
func (c *collection) DropIndex(ctx context.Context, indexName string) error {
ctx, span := tracer.Start(ctx)
defer span.End()

ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return err
Expand Down Expand Up @@ -463,6 +469,9 @@ func (c *collection) loadIndexes(ctx context.Context) error {

// GetIndexes returns all indexes for the collection.
func (c *collection) GetIndexes(ctx context.Context) ([]client.IndexDescription, error) {
ctx, span := tracer.Start(ctx)
defer span.End()

ctx, txn, err := ensureContextTxn(ctx, c.db, false)
if err != nil {
return nil, err
Expand Down
Loading
Loading