Skip to content

feat(services): add OpenTelemetry tracing to Storage, Function, Database, and Cache services#369

Closed
poyrazK wants to merge 3 commits intomainfrom
feat/opentelemetry-tracing
Closed

feat(services): add OpenTelemetry tracing to Storage, Function, Database, and Cache services#369
poyrazK wants to merge 3 commits intomainfrom
feat/opentelemetry-tracing

Conversation

@poyrazK
Copy link
Copy Markdown
Owner

@poyrazK poyrazK commented Apr 30, 2026

Summary

Instrument StorageService, FunctionService, DatabaseService, and CacheService with OpenTelemetry spans for improved observability. Closes #339.

Changes

  • StorageService (storage-service): Upload, Download, CreateBucket, DeleteBucket
  • FunctionService (function-service): CreateFunction, InvokeFunction, GetFunctionLogs
  • DatabaseService (database-service): CreateDatabase, RestoreDatabase, doRotateCredentials
  • CacheService (cache-service): CreateCache, GetCacheStats

Implementation

Each method follows the established OTel pattern:

tracer := otel.Tracer(tracerName)
_, span := tracer.Start(ctx, "Service.Method",
    trace.WithAttributes(
        attribute.String("field", value),
    ))
defer span.End()
// ... existing logic ...
if err != nil {
    span.RecordError(err)
    return nil, err
}

Uses _ for the span-wrapped context to avoid propagating trace context into repo/mock calls (which would break mock equality assertions in unit tests).

Test Plan

  • go build ./internal/core/services/...
  • go test ./internal/core/services/... -count=1 (all pass)

Verification

With TRACING_ENABLED=true and Jaeger running locally, traces will appear at http://localhost:16686.

poyrazK added 3 commits April 30, 2026 13:32
Forward iteration with slice removal during the loop causes the next
element to be skipped (classic off-by-one bug). When streams[i] is
removed, all subsequent elements shift left, but the loop's i++ then
moves past the element that just shifted into position i.

Fix by iterating backwards - removing streams[i] doesn't affect
indices of elements we haven't processed yet (0 through i-1).
Addresses multiple DoS vectors from unbounded io operations and maps:

- storage_handler.go: Wrap Upload/UploadPart/ServePresignedUpload
  bodies with io.LimitReader(maxUploadSize=5GB)
- core/services/storage.go: Wrap UploadPart with io.LimitReader(maxPartSize=5GB)
- workers/pipeline_worker.go: Reject payloads >10MB before json.Unmarshal
- core/services/instance.go: Wrap stats stream with io.LimitReader(maxStatsSize=1MB)
- core/services/cache.go: Same for cache stats stream
- core/services/function.go: Wrap log reader with io.LimitReader(maxLogSize=1MB)
- core/services/auth.go: Purge expired lockout/failure map entries
  probabilistically on each incrementFailure to prevent unbounded growth
- storage/coordinator/service.go: Track totalSize and reject if >5GB
- storage/node/store.go: Wrap WriteStream and Assemble with size checks
- repositories/filesystem/adapter.go: Wrap Write with io.LimitReader(maxObjectSize=5GB)
…ase, and Cache services

Instrument the following high-value methods with spans following the existing
tracing pattern (otel.Tracer + defer span.End + span.RecordError):

- StorageService: Upload, Download, CreateBucket, DeleteBucket
- FunctionService: CreateFunction, InvokeFunction, GetFunctionLogs
- DatabaseService: CreateDatabase, RestoreDatabase, doRotateCredentials
- CacheService: CreateCache, GetCacheStats

Uses tracer name constants (e.g. "storage-service") for consistency with
existing otelgin middleware and pkg/tracing infrastructure.

Closes #339.
Copilot AI review requested due to automatic review settings April 30, 2026 12:23
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@poyrazK has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 57 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fb03157e-1d37-4d7a-8ad1-e42f135970d3

📥 Commits

Reviewing files that changed from the base of the PR and between d16bbdd and 80cef5c.

📒 Files selected for processing (11)
  • internal/core/services/auth.go
  • internal/core/services/cache.go
  • internal/core/services/database.go
  • internal/core/services/function.go
  • internal/core/services/instance.go
  • internal/core/services/storage.go
  • internal/handlers/storage_handler.go
  • internal/repositories/filesystem/adapter.go
  • internal/storage/coordinator/service.go
  • internal/storage/node/store.go
  • internal/workers/pipeline_worker.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/opentelemetry-tracing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 38 minutes and 57 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement distributed tracing with OpenTelemetry and Jaeger

2 participants