@mytechtoday/augment-extensions 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/augment-extensions/coding-standards/c/CHANGELOG.md +55 -0
- package/augment-extensions/coding-standards/c/LICENSE +22 -0
- package/augment-extensions/coding-standards/c/README.md +167 -0
- package/augment-extensions/coding-standards/c/config/defaults.json +26 -0
- package/augment-extensions/coding-standards/c/config/examples/embedded.yaml +25 -0
- package/augment-extensions/coding-standards/c/config/examples/systems.json +31 -0
- package/augment-extensions/coding-standards/c/config/schema.json +244 -0
- package/augment-extensions/coding-standards/c/docs/API.md +613 -0
- package/augment-extensions/coding-standards/c/docs/CONFIGURATION.md +259 -0
- package/augment-extensions/coding-standards/c/docs/USER_GUIDE.md +567 -0
- package/augment-extensions/coding-standards/c/examples/drivers/Makefile +33 -0
- package/augment-extensions/coding-standards/c/examples/drivers/README.md +192 -0
- package/augment-extensions/coding-standards/c/examples/drivers/dma-example.c +224 -0
- package/augment-extensions/coding-standards/c/examples/drivers/example.dts +64 -0
- package/augment-extensions/coding-standards/c/examples/drivers/platform-driver.c +174 -0
- package/augment-extensions/coding-standards/c/examples/embedded/README.md +167 -0
- package/augment-extensions/coding-standards/c/examples/embedded/gpio-control.c +172 -0
- package/augment-extensions/coding-standards/c/examples/embedded/timer-isr.c +198 -0
- package/augment-extensions/coding-standards/c/examples/embedded/uart-communication.c +212 -0
- package/augment-extensions/coding-standards/c/examples/kernel/Makefile +82 -0
- package/augment-extensions/coding-standards/c/examples/kernel/README.md +168 -0
- package/augment-extensions/coding-standards/c/examples/kernel/char-device.c +198 -0
- package/augment-extensions/coding-standards/c/examples/kernel/proc-file.c +131 -0
- package/augment-extensions/coding-standards/c/examples/kernel/simple-module.c +111 -0
- package/augment-extensions/coding-standards/c/examples/legacy/Makefile +62 -0
- package/augment-extensions/coding-standards/c/examples/legacy/README.md +255 -0
- package/augment-extensions/coding-standards/c/examples/legacy/c89-to-c11-migration.c +268 -0
- package/augment-extensions/coding-standards/c/examples/legacy/compatibility-layer.c +239 -0
- package/augment-extensions/coding-standards/c/examples/networking/Makefile +35 -0
- package/augment-extensions/coding-standards/c/examples/networking/README.md +207 -0
- package/augment-extensions/coding-standards/c/examples/networking/protocol-parser.c +270 -0
- package/augment-extensions/coding-standards/c/examples/networking/tcp-server.c +197 -0
- package/augment-extensions/coding-standards/c/examples/networking/udp-multicast.c +220 -0
- package/augment-extensions/coding-standards/c/examples/realtime/Makefile +53 -0
- package/augment-extensions/coding-standards/c/examples/realtime/README.md +199 -0
- package/augment-extensions/coding-standards/c/examples/realtime/deadline-monitoring.c +260 -0
- package/augment-extensions/coding-standards/c/examples/realtime/priority-scheduling.c +258 -0
- package/augment-extensions/coding-standards/c/examples/systems/Makefile +34 -0
- package/augment-extensions/coding-standards/c/examples/systems/README.md +123 -0
- package/augment-extensions/coding-standards/c/examples/systems/ipc-pipes.c +181 -0
- package/augment-extensions/coding-standards/c/examples/systems/process-management.c +153 -0
- package/augment-extensions/coding-standards/c/examples/systems/signal-handling.c +162 -0
- package/augment-extensions/coding-standards/c/module.json +149 -0
- package/augment-extensions/coding-standards/c/rules/categories/drivers.md +635 -0
- package/augment-extensions/coding-standards/c/rules/categories/embedded.md +510 -0
- package/augment-extensions/coding-standards/c/rules/categories/kernel.md +653 -0
- package/augment-extensions/coding-standards/c/rules/categories/legacy.md +526 -0
- package/augment-extensions/coding-standards/c/rules/categories/networking.md +735 -0
- package/augment-extensions/coding-standards/c/rules/categories/realtime.md +631 -0
- package/augment-extensions/coding-standards/c/rules/categories/systems.md +586 -0
- package/augment-extensions/coding-standards/c/rules/universal/const-correctness.md +275 -0
- package/augment-extensions/coding-standards/c/rules/universal/documentation.md +251 -0
- package/augment-extensions/coding-standards/c/rules/universal/error-handling.md +250 -0
- package/augment-extensions/coding-standards/c/rules/universal/header-guards.md +254 -0
- package/augment-extensions/coding-standards/c/rules/universal/memory-safety.md +233 -0
- package/augment-extensions/coding-standards/c/rules/universal/naming.md +146 -0
- package/augment-extensions/coding-standards/c/src/conflict-detector.ts +461 -0
- package/augment-extensions/coding-standards/c/src/prompt-generator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-evaluator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-override.ts +427 -0
- package/augment-extensions/coding-standards/c/src/template-engine.ts +217 -0
- package/augment-extensions/coding-standards/c/templates/prompts/drivers.txt +191 -0
- package/augment-extensions/coding-standards/c/templates/prompts/embedded.txt +164 -0
- package/augment-extensions/coding-standards/c/templates/prompts/kernel.txt +175 -0
- package/augment-extensions/coding-standards/c/templates/prompts/legacy.txt +280 -0
- package/augment-extensions/coding-standards/c/templates/prompts/networking.txt +259 -0
- package/augment-extensions/coding-standards/c/templates/prompts/realtime.txt +219 -0
- package/augment-extensions/coding-standards/c/templates/prompts/systems.txt +147 -0
- package/augment-extensions/coding-standards/c/tests/integration/category-specific.test.ts +356 -0
- package/augment-extensions/coding-standards/c/tests/integration/end-to-end-workflow.test.ts +377 -0
- package/augment-extensions/coding-standards/c/tests/performance/benchmarks.test.ts +407 -0
- package/augment-extensions/coding-standards/c/tests/unit/config-manager.test.ts +345 -0
- package/augment-extensions/coding-standards/c/tests/unit/conflict-detector.test.ts +294 -0
- package/augment-extensions/coding-standards/c/tests/unit/prompt-generator.test.ts +174 -0
- package/augment-extensions/coding-standards/c/tests/unit/registry.test.ts +313 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-evaluator.test.ts +318 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-override.test.ts +326 -0
- package/augment-extensions/coding-standards/c/tests/unit/template-engine.test.ts +314 -0
- package/augment-extensions/coding-standards/go/CHARACTER-COUNT-REPORT.md +135 -0
- package/augment-extensions/coding-standards/go/PHASE1-COMPLETION.md +146 -0
- package/augment-extensions/coding-standards/go/PHASE4-COMPLETION.md +184 -0
- package/augment-extensions/coding-standards/go/README.md +200 -0
- package/augment-extensions/coding-standards/go/VALIDATION-CHECKLIST.md +154 -0
- package/augment-extensions/coding-standards/go/config/examples/example-cli.json +15 -0
- package/augment-extensions/coding-standards/go/config/examples/example-microservices.json +21 -0
- package/augment-extensions/coding-standards/go/config/examples/example-multi-category.yaml +24 -0
- package/augment-extensions/coding-standards/go/config/examples/example-web.json +15 -0
- package/augment-extensions/coding-standards/go/config/schema.json +110 -0
- package/augment-extensions/coding-standards/go/docs/CATEGORIES.md +221 -0
- package/augment-extensions/coding-standards/go/docs/CONFIGURATION.md +198 -0
- package/augment-extensions/coding-standards/go/docs/TROUBLESHOOTING.md +285 -0
- package/augment-extensions/coding-standards/go/examples/cli/cobra-app.go +287 -0
- package/augment-extensions/coding-standards/go/examples/cloud-native-app.go +217 -0
- package/augment-extensions/coding-standards/go/examples/devops-tool.go +250 -0
- package/augment-extensions/coding-standards/go/examples/distributed-system.go +247 -0
- package/augment-extensions/coding-standards/go/examples/microservices/grpc-service.go +253 -0
- package/augment-extensions/coding-standards/go/examples/rest-api.go +270 -0
- package/augment-extensions/coding-standards/go/examples/web/http-server.go +224 -0
- package/augment-extensions/coding-standards/go/module.json +139 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/api-versioning.md +149 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rate-limiting.md +209 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rest-api-design.md +183 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/cloud-config.md +193 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/health-checks.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/kubernetes.md +180 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/automation.md +179 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/ci-cd-integration.md +147 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/infrastructure-as-code.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/caching.md +150 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/consensus.md +187 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/event-sourcing.md +246 -0
- package/augment-extensions/coding-standards/go/rules/cli/command-parsing.md +264 -0
- package/augment-extensions/coding-standards/go/rules/cli/configuration.md +268 -0
- package/augment-extensions/coding-standards/go/rules/cli/cross-platform.md +324 -0
- package/augment-extensions/coding-standards/go/rules/microservices/distributed-tracing.md +253 -0
- package/augment-extensions/coding-standards/go/rules/microservices/grpc.md +257 -0
- package/augment-extensions/coding-standards/go/rules/microservices/metrics.md +278 -0
- package/augment-extensions/coding-standards/go/rules/microservices/service-discovery.md +249 -0
- package/augment-extensions/coding-standards/go/rules/universal/code-organization.md +221 -0
- package/augment-extensions/coding-standards/go/rules/universal/documentation.md +269 -0
- package/augment-extensions/coding-standards/go/rules/universal/performance.md +323 -0
- package/augment-extensions/coding-standards/go/rules/universal/testing.md +162 -0
- package/augment-extensions/coding-standards/go/rules/web/graceful-shutdown.md +249 -0
- package/augment-extensions/coding-standards/go/rules/web/http-handlers.md +164 -0
- package/augment-extensions/coding-standards/go/rules/web/middleware.md +234 -0
- package/augment-extensions/coding-standards/go/rules/web/routing.md +251 -0
- package/augment-extensions/coding-standards/go/templates/prompts/api.md +160 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cli.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cloud-native.md +121 -0
- package/augment-extensions/coding-standards/go/templates/prompts/devops.md +146 -0
- package/augment-extensions/coding-standards/go/templates/prompts/distributed.md +133 -0
- package/augment-extensions/coding-standards/go/templates/prompts/microservices.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/web.md +181 -0
- package/augment-extensions/coding-standards/go/tests/integration/module-integration.test.ts +164 -0
- package/augment-extensions/coding-standards/go/tests/unit/category-selection.test.ts +147 -0
- package/augment-extensions/coding-standards/go/tests/unit/module-structure.test.ts +154 -0
- package/augment-extensions/coding-standards/go/tests/validate-character-count.ps1 +13 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.ps1 +148 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.sh +135 -0
- package/cli/dist/analysis/ast-parser.d.ts +47 -0
- package/cli/dist/analysis/ast-parser.d.ts.map +1 -0
- package/cli/dist/analysis/ast-parser.js +161 -0
- package/cli/dist/analysis/ast-parser.js.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts +27 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.js +189 -0
- package/cli/dist/analysis/complexity-analyzer.js.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts +23 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.js +237 -0
- package/cli/dist/analysis/dependency-analyzer.js.map +1 -0
- package/cli/dist/analysis/index.d.ts +9 -0
- package/cli/dist/analysis/index.d.ts.map +1 -0
- package/cli/dist/analysis/index.js +25 -0
- package/cli/dist/analysis/index.js.map +1 -0
- package/cli/dist/analysis/security-scanner.d.ts +11 -0
- package/cli/dist/analysis/security-scanner.d.ts.map +1 -0
- package/cli/dist/analysis/security-scanner.js +294 -0
- package/cli/dist/analysis/security-scanner.js.map +1 -0
- package/cli/dist/analysis/types.d.ts +151 -0
- package/cli/dist/analysis/types.d.ts.map +1 -0
- package/cli/dist/analysis/types.js +6 -0
- package/cli/dist/analysis/types.js.map +1 -0
- package/cli/dist/cli.js +24 -0
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/code-analysis.d.ts +11 -0
- package/cli/dist/commands/code-analysis.d.ts.map +1 -0
- package/cli/dist/commands/code-analysis.js +412 -0
- package/cli/dist/commands/code-analysis.js.map +1 -0
- package/modules.md +99 -3
- package/package.json +14 -2
- package/cli/dist/commands/agent.d.ts +0 -37
- package/cli/dist/commands/agent.d.ts.map +0 -1
- package/cli/dist/commands/agent.js +0 -222
- package/cli/dist/commands/agent.js.map +0 -1
- package/cli/dist/commands/beads.d.ts +0 -64
- package/cli/dist/commands/beads.d.ts.map +0 -1
- package/cli/dist/commands/beads.js +0 -377
- package/cli/dist/commands/beads.js.map +0 -1
- package/cli/dist/commands/change.d.ts +0 -54
- package/cli/dist/commands/change.d.ts.map +0 -1
- package/cli/dist/commands/change.js +0 -243
- package/cli/dist/commands/change.js.map +0 -1
- package/cli/dist/commands/clean.d.ts +0 -15
- package/cli/dist/commands/clean.d.ts.map +0 -1
- package/cli/dist/commands/clean.js +0 -63
- package/cli/dist/commands/clean.js.map +0 -1
- package/cli/dist/commands/clone.d.ts +0 -15
- package/cli/dist/commands/clone.d.ts.map +0 -1
- package/cli/dist/commands/clone.js +0 -49
- package/cli/dist/commands/clone.js.map +0 -1
- package/cli/dist/commands/config.d.ts +0 -33
- package/cli/dist/commands/config.d.ts.map +0 -1
- package/cli/dist/commands/config.js +0 -166
- package/cli/dist/commands/config.js.map +0 -1
- package/cli/dist/commands/context.d.ts +0 -38
- package/cli/dist/commands/context.d.ts.map +0 -1
- package/cli/dist/commands/context.js +0 -205
- package/cli/dist/commands/context.js.map +0 -1
- package/cli/dist/commands/create.d.ts +0 -18
- package/cli/dist/commands/create.d.ts.map +0 -1
- package/cli/dist/commands/create.js +0 -178
- package/cli/dist/commands/create.js.map +0 -1
- package/cli/dist/commands/diff.d.ts +0 -19
- package/cli/dist/commands/diff.d.ts.map +0 -1
- package/cli/dist/commands/diff.js +0 -104
- package/cli/dist/commands/diff.js.map +0 -1
- package/cli/dist/commands/doctor.d.ts +0 -14
- package/cli/dist/commands/doctor.d.ts.map +0 -1
- package/cli/dist/commands/doctor.js +0 -62
- package/cli/dist/commands/doctor.js.map +0 -1
- package/cli/dist/commands/export.d.ts +0 -28
- package/cli/dist/commands/export.d.ts.map +0 -1
- package/cli/dist/commands/export.js +0 -135
- package/cli/dist/commands/export.js.map +0 -1
- package/cli/dist/commands/import.d.ts +0 -23
- package/cli/dist/commands/import.d.ts.map +0 -1
- package/cli/dist/commands/import.js +0 -118
- package/cli/dist/commands/import.js.map +0 -1
- package/cli/dist/commands/prompt.d.ts +0 -45
- package/cli/dist/commands/prompt.d.ts.map +0 -1
- package/cli/dist/commands/prompt.js +0 -223
- package/cli/dist/commands/prompt.js.map +0 -1
- package/cli/dist/commands/spec.d.ts +0 -57
- package/cli/dist/commands/spec.d.ts.map +0 -1
- package/cli/dist/commands/spec.js +0 -279
- package/cli/dist/commands/spec.js.map +0 -1
- package/cli/dist/commands/stats.d.ts +0 -18
- package/cli/dist/commands/stats.d.ts.map +0 -1
- package/cli/dist/commands/stats.js +0 -85
- package/cli/dist/commands/stats.js.map +0 -1
- package/cli/dist/commands/task.d.ts +0 -65
- package/cli/dist/commands/task.d.ts.map +0 -1
- package/cli/dist/commands/task.js +0 -282
- package/cli/dist/commands/task.js.map +0 -1
- package/cli/dist/commands/template.d.ts +0 -17
- package/cli/dist/commands/template.d.ts.map +0 -1
- package/cli/dist/commands/template.js +0 -55
- package/cli/dist/commands/template.js.map +0 -1
- package/cli/dist/utils/agent-config.d.ts +0 -129
- package/cli/dist/utils/agent-config.d.ts.map +0 -1
- package/cli/dist/utils/agent-config.js +0 -297
- package/cli/dist/utils/agent-config.js.map +0 -1
- package/cli/dist/utils/beads-graph.d.ts +0 -17
- package/cli/dist/utils/beads-graph.d.ts.map +0 -1
- package/cli/dist/utils/beads-graph.js +0 -150
- package/cli/dist/utils/beads-graph.js.map +0 -1
- package/cli/dist/utils/beads-integration.d.ts +0 -112
- package/cli/dist/utils/beads-integration.d.ts.map +0 -1
- package/cli/dist/utils/beads-integration.js +0 -312
- package/cli/dist/utils/beads-integration.js.map +0 -1
- package/cli/dist/utils/beads-reporter.d.ts +0 -17
- package/cli/dist/utils/beads-reporter.d.ts.map +0 -1
- package/cli/dist/utils/beads-reporter.js +0 -160
- package/cli/dist/utils/beads-reporter.js.map +0 -1
- package/cli/dist/utils/cache-manager.d.ts +0 -55
- package/cli/dist/utils/cache-manager.d.ts.map +0 -1
- package/cli/dist/utils/cache-manager.js +0 -150
- package/cli/dist/utils/cache-manager.js.map +0 -1
- package/cli/dist/utils/change-manager.d.ts +0 -70
- package/cli/dist/utils/change-manager.d.ts.map +0 -1
- package/cli/dist/utils/change-manager.js +0 -412
- package/cli/dist/utils/change-manager.js.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.d.ts +0 -66
- package/cli/dist/utils/config-manager-enhanced.d.ts.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.js +0 -77
- package/cli/dist/utils/config-manager-enhanced.js.map +0 -1
- package/cli/dist/utils/context-manager.d.ts +0 -96
- package/cli/dist/utils/context-manager.d.ts.map +0 -1
- package/cli/dist/utils/context-manager.js +0 -258
- package/cli/dist/utils/context-manager.js.map +0 -1
- package/cli/dist/utils/diff-engine.d.ts +0 -78
- package/cli/dist/utils/diff-engine.d.ts.map +0 -1
- package/cli/dist/utils/diff-engine.js +0 -233
- package/cli/dist/utils/diff-engine.js.map +0 -1
- package/cli/dist/utils/export-system.d.ts +0 -101
- package/cli/dist/utils/export-system.d.ts.map +0 -1
- package/cli/dist/utils/export-system.js +0 -289
- package/cli/dist/utils/export-system.js.map +0 -1
- package/cli/dist/utils/health-checker.d.ts +0 -66
- package/cli/dist/utils/health-checker.d.ts.map +0 -1
- package/cli/dist/utils/health-checker.js +0 -285
- package/cli/dist/utils/health-checker.js.map +0 -1
- package/cli/dist/utils/import-system.d.ts +0 -74
- package/cli/dist/utils/import-system.d.ts.map +0 -1
- package/cli/dist/utils/import-system.js +0 -317
- package/cli/dist/utils/import-system.js.map +0 -1
- package/cli/dist/utils/module-cloner.d.ts +0 -40
- package/cli/dist/utils/module-cloner.d.ts.map +0 -1
- package/cli/dist/utils/module-cloner.js +0 -136
- package/cli/dist/utils/module-cloner.js.map +0 -1
- package/cli/dist/utils/prompt-manager.d.ts +0 -90
- package/cli/dist/utils/prompt-manager.d.ts.map +0 -1
- package/cli/dist/utils/prompt-manager.js +0 -302
- package/cli/dist/utils/prompt-manager.js.map +0 -1
- package/cli/dist/utils/spec-manager.d.ts +0 -65
- package/cli/dist/utils/spec-manager.d.ts.map +0 -1
- package/cli/dist/utils/spec-manager.js +0 -329
- package/cli/dist/utils/spec-manager.js.map +0 -1
- package/cli/dist/utils/stats-collector.d.ts +0 -74
- package/cli/dist/utils/stats-collector.d.ts.map +0 -1
- package/cli/dist/utils/stats-collector.js +0 -164
- package/cli/dist/utils/stats-collector.js.map +0 -1
- package/cli/dist/utils/template-engine.d.ts +0 -47
- package/cli/dist/utils/template-engine.d.ts.map +0 -1
- package/cli/dist/utils/template-engine.js +0 -204
- package/cli/dist/utils/template-engine.js.map +0 -1
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# Go Microservices - Distributed Tracing
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Distributed tracing enables tracking requests across multiple microservices. This document defines best practices for implementing distributed tracing using OpenTelemetry in Go.
|
|
6
|
+
|
|
7
|
+
## Core Principles
|
|
8
|
+
|
|
9
|
+
1. **Context Propagation**: Pass trace context across service boundaries
|
|
10
|
+
2. **Span Creation**: Create spans for significant operations
|
|
11
|
+
3. **Attribute Enrichment**: Add relevant attributes to spans
|
|
12
|
+
4. **Error Recording**: Record errors and exceptions in spans
|
|
13
|
+
5. **Sampling**: Use appropriate sampling strategies
|
|
14
|
+
|
|
15
|
+
## Rules
|
|
16
|
+
|
|
17
|
+
### GOL.3.2.3.1: Initialize OpenTelemetry Tracer
|
|
18
|
+
|
|
19
|
+
**Rule**: Initialize OpenTelemetry tracer provider on application startup.
|
|
20
|
+
|
|
21
|
+
**Severity**: ERROR
|
|
22
|
+
|
|
23
|
+
**Rationale**: Enables distributed tracing across all services.
|
|
24
|
+
|
|
25
|
+
**✅ Good**:
|
|
26
|
+
```go
|
|
27
|
+
import (
|
|
28
|
+
"go.opentelemetry.io/otel"
|
|
29
|
+
"go.opentelemetry.io/otel/exporters/jaeger"
|
|
30
|
+
"go.opentelemetry.io/otel/sdk/resource"
|
|
31
|
+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
|
32
|
+
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
func initTracer(serviceName, jaegerEndpoint string) (*sdktrace.TracerProvider, error) {
|
|
36
|
+
// Create Jaeger exporter
|
|
37
|
+
exporter, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(jaegerEndpoint)))
|
|
38
|
+
if err != nil {
|
|
39
|
+
return nil, err
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Create resource with service name
|
|
43
|
+
res, err := resource.New(
|
|
44
|
+
context.Background(),
|
|
45
|
+
resource.WithAttributes(
|
|
46
|
+
semconv.ServiceNameKey.String(serviceName),
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
if err != nil {
|
|
50
|
+
return nil, err
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Create tracer provider
|
|
54
|
+
tp := sdktrace.NewTracerProvider(
|
|
55
|
+
sdktrace.WithBatcher(exporter),
|
|
56
|
+
sdktrace.WithResource(res),
|
|
57
|
+
sdktrace.WithSampler(sdktrace.AlwaysSample()),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
// Set global tracer provider
|
|
61
|
+
otel.SetTracerProvider(tp)
|
|
62
|
+
|
|
63
|
+
return tp, nil
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func main() {
|
|
67
|
+
tp, err := initTracer("user-service", "http://jaeger:14268/api/traces")
|
|
68
|
+
if err != nil {
|
|
69
|
+
log.Fatal(err)
|
|
70
|
+
}
|
|
71
|
+
defer func() {
|
|
72
|
+
if err := tp.Shutdown(context.Background()); err != nil {
|
|
73
|
+
log.Printf("Error shutting down tracer provider: %v", err)
|
|
74
|
+
}
|
|
75
|
+
}()
|
|
76
|
+
|
|
77
|
+
// Start server...
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### GOL.3.2.3.2: Create Spans for Operations
|
|
82
|
+
|
|
83
|
+
**Rule**: Create spans for significant operations (HTTP requests, database queries, external calls).
|
|
84
|
+
|
|
85
|
+
**Severity**: WARNING
|
|
86
|
+
|
|
87
|
+
**✅ Good**:
|
|
88
|
+
```go
|
|
89
|
+
import (
|
|
90
|
+
"go.opentelemetry.io/otel"
|
|
91
|
+
"go.opentelemetry.io/otel/attribute"
|
|
92
|
+
"go.opentelemetry.io/otel/codes"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
func (s *UserService) GetUser(ctx context.Context, id int64) (*User, error) {
|
|
96
|
+
tracer := otel.Tracer("user-service")
|
|
97
|
+
|
|
98
|
+
// Create span
|
|
99
|
+
ctx, span := tracer.Start(ctx, "GetUser")
|
|
100
|
+
defer span.End()
|
|
101
|
+
|
|
102
|
+
// Add attributes
|
|
103
|
+
span.SetAttributes(
|
|
104
|
+
attribute.Int64("user.id", id),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
// Perform operation
|
|
108
|
+
user, err := s.repo.GetUser(ctx, id)
|
|
109
|
+
if err != nil {
|
|
110
|
+
// Record error
|
|
111
|
+
span.RecordError(err)
|
|
112
|
+
span.SetStatus(codes.Error, err.Error())
|
|
113
|
+
return nil, err
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Add result attributes
|
|
117
|
+
span.SetAttributes(
|
|
118
|
+
attribute.String("user.name", user.Name),
|
|
119
|
+
attribute.String("user.email", user.Email),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
return user, nil
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### GOL.3.2.3.3: Propagate Context in HTTP Requests
|
|
127
|
+
|
|
128
|
+
**Rule**: Propagate trace context in HTTP headers for cross-service calls.
|
|
129
|
+
|
|
130
|
+
**Severity**: ERROR
|
|
131
|
+
|
|
132
|
+
**Rationale**: Enables end-to-end tracing across service boundaries.
|
|
133
|
+
|
|
134
|
+
**✅ Good - HTTP Client**:
|
|
135
|
+
```go
|
|
136
|
+
import (
|
|
137
|
+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
func NewHTTPClient() *http.Client {
|
|
141
|
+
return &http.Client{
|
|
142
|
+
Transport: otelhttp.NewTransport(http.DefaultTransport),
|
|
143
|
+
Timeout: 30 * time.Second,
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
func (c *Client) CallExternalService(ctx context.Context, url string) (*Response, error) {
|
|
148
|
+
tracer := otel.Tracer("user-service")
|
|
149
|
+
ctx, span := tracer.Start(ctx, "CallExternalService")
|
|
150
|
+
defer span.End()
|
|
151
|
+
|
|
152
|
+
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
|
153
|
+
if err != nil {
|
|
154
|
+
span.RecordError(err)
|
|
155
|
+
return nil, err
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Context is automatically propagated via otelhttp.Transport
|
|
159
|
+
resp, err := c.httpClient.Do(req)
|
|
160
|
+
if err != nil {
|
|
161
|
+
span.RecordError(err)
|
|
162
|
+
return nil, err
|
|
163
|
+
}
|
|
164
|
+
defer resp.Body.Close()
|
|
165
|
+
|
|
166
|
+
// Process response...
|
|
167
|
+
return processResponse(resp)
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**✅ Good - HTTP Server**:
|
|
172
|
+
```go
|
|
173
|
+
func setupRoutes() http.Handler {
|
|
174
|
+
r := chi.NewRouter()
|
|
175
|
+
|
|
176
|
+
// Add OpenTelemetry middleware
|
|
177
|
+
r.Use(otelhttp.NewMiddleware("user-service"))
|
|
178
|
+
|
|
179
|
+
r.Get("/users/{id}", handleGetUser)
|
|
180
|
+
|
|
181
|
+
return r
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### GOL.3.2.3.4: Instrument gRPC with Tracing
|
|
186
|
+
|
|
187
|
+
**Rule**: Use OpenTelemetry interceptors for gRPC tracing.
|
|
188
|
+
|
|
189
|
+
**Severity**: WARNING
|
|
190
|
+
|
|
191
|
+
**✅ Good**:
|
|
192
|
+
```go
|
|
193
|
+
import (
|
|
194
|
+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
// Server
|
|
198
|
+
func NewGRPCServer() *grpc.Server {
|
|
199
|
+
return grpc.NewServer(
|
|
200
|
+
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor()),
|
|
201
|
+
grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor()),
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Client
|
|
206
|
+
func NewGRPCClient(addr string) (*grpc.ClientConn, error) {
|
|
207
|
+
return grpc.Dial(addr,
|
|
208
|
+
grpc.WithInsecure(),
|
|
209
|
+
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()),
|
|
210
|
+
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()),
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### GOL.3.2.3.5: Add Custom Span Attributes
|
|
216
|
+
|
|
217
|
+
**Rule**: Add relevant business context as span attributes.
|
|
218
|
+
|
|
219
|
+
**Severity**: INFO
|
|
220
|
+
|
|
221
|
+
**✅ Good**:
|
|
222
|
+
```go
|
|
223
|
+
func (s *OrderService) CreateOrder(ctx context.Context, order *Order) error {
|
|
224
|
+
tracer := otel.Tracer("order-service")
|
|
225
|
+
ctx, span := tracer.Start(ctx, "CreateOrder")
|
|
226
|
+
defer span.End()
|
|
227
|
+
|
|
228
|
+
// Add business context
|
|
229
|
+
span.SetAttributes(
|
|
230
|
+
attribute.String("order.id", order.ID),
|
|
231
|
+
attribute.String("customer.id", order.CustomerID),
|
|
232
|
+
attribute.Float64("order.total", order.Total),
|
|
233
|
+
attribute.Int("order.item_count", len(order.Items)),
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
// Process order...
|
|
237
|
+
if err := s.processOrder(ctx, order); err != nil {
|
|
238
|
+
span.RecordError(err)
|
|
239
|
+
span.SetStatus(codes.Error, "failed to process order")
|
|
240
|
+
return err
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
span.SetStatus(codes.Ok, "order created successfully")
|
|
244
|
+
return nil
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## References
|
|
249
|
+
|
|
250
|
+
- [OpenTelemetry Go](https://opentelemetry.io/docs/instrumentation/go/)
|
|
251
|
+
- [Jaeger Tracing](https://www.jaegertracing.io/)
|
|
252
|
+
- [OpenTelemetry Best Practices](https://opentelemetry.io/docs/concepts/signals/traces/)
|
|
253
|
+
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# Go Microservices - gRPC Patterns
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
gRPC is a high-performance RPC framework ideal for microservices communication. This document defines best practices for implementing gRPC services in Go.
|
|
6
|
+
|
|
7
|
+
## Core Principles
|
|
8
|
+
|
|
9
|
+
1. **Protocol Buffers**: Use proto3 for service definitions
|
|
10
|
+
2. **Error Handling**: Use gRPC status codes and error details
|
|
11
|
+
3. **Streaming**: Leverage streaming for large datasets and real-time updates
|
|
12
|
+
4. **Interceptors**: Use interceptors for cross-cutting concerns
|
|
13
|
+
5. **Context Propagation**: Pass context for timeouts and cancellation
|
|
14
|
+
|
|
15
|
+
## Rules
|
|
16
|
+
|
|
17
|
+
### GOL.3.2.1.1: Define Services with Protocol Buffers
|
|
18
|
+
|
|
19
|
+
**Rule**: Define all gRPC services using Protocol Buffers (proto3).
|
|
20
|
+
|
|
21
|
+
**Severity**: ERROR
|
|
22
|
+
|
|
23
|
+
**Rationale**: Protocol Buffers provide type safety, versioning, and cross-language compatibility.
|
|
24
|
+
|
|
25
|
+
**✅ Good - user.proto**:
|
|
26
|
+
```protobuf
|
|
27
|
+
syntax = "proto3";
|
|
28
|
+
|
|
29
|
+
package user.v1;
|
|
30
|
+
|
|
31
|
+
option go_package = "github.com/example/user/v1;userv1";
|
|
32
|
+
|
|
33
|
+
service UserService {
|
|
34
|
+
rpc GetUser(GetUserRequest) returns (GetUserResponse);
|
|
35
|
+
rpc ListUsers(ListUsersRequest) returns (ListUsersResponse);
|
|
36
|
+
rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
|
|
37
|
+
rpc UpdateUser(UpdateUserRequest) returns (UpdateUserResponse);
|
|
38
|
+
rpc DeleteUser(DeleteUserRequest) returns (DeleteUserResponse);
|
|
39
|
+
|
|
40
|
+
// Streaming example
|
|
41
|
+
rpc StreamUsers(StreamUsersRequest) returns (stream User);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
message User {
|
|
45
|
+
int64 id = 1;
|
|
46
|
+
string name = 2;
|
|
47
|
+
string email = 3;
|
|
48
|
+
int64 created_at = 4;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
message GetUserRequest {
|
|
52
|
+
int64 id = 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
message GetUserResponse {
|
|
56
|
+
User user = 1;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### GOL.3.2.1.2: Implement Proper Error Handling
|
|
61
|
+
|
|
62
|
+
**Rule**: Use gRPC status codes and structured error details.
|
|
63
|
+
|
|
64
|
+
**Severity**: ERROR
|
|
65
|
+
|
|
66
|
+
**Rationale**: Proper error handling enables clients to handle failures appropriately.
|
|
67
|
+
|
|
68
|
+
**✅ Good**:
|
|
69
|
+
```go
|
|
70
|
+
import (
|
|
71
|
+
"google.golang.org/grpc/codes"
|
|
72
|
+
"google.golang.org/grpc/status"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
func (s *UserService) GetUser(ctx context.Context, req *userv1.GetUserRequest) (*userv1.GetUserResponse, error) {
|
|
76
|
+
if req.Id <= 0 {
|
|
77
|
+
return nil, status.Error(codes.InvalidArgument, "user ID must be positive")
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
user, err := s.repo.GetUser(ctx, req.Id)
|
|
81
|
+
if err != nil {
|
|
82
|
+
if errors.Is(err, ErrNotFound) {
|
|
83
|
+
return nil, status.Error(codes.NotFound, "user not found")
|
|
84
|
+
}
|
|
85
|
+
return nil, status.Error(codes.Internal, "failed to get user")
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return &userv1.GetUserResponse{
|
|
89
|
+
User: &userv1.User{
|
|
90
|
+
Id: user.ID,
|
|
91
|
+
Name: user.Name,
|
|
92
|
+
Email: user.Email,
|
|
93
|
+
CreatedAt: user.CreatedAt.Unix(),
|
|
94
|
+
},
|
|
95
|
+
}, nil
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**gRPC Status Code Mapping**:
|
|
100
|
+
- `codes.OK` - Success
|
|
101
|
+
- `codes.InvalidArgument` - Invalid input
|
|
102
|
+
- `codes.NotFound` - Resource not found
|
|
103
|
+
- `codes.AlreadyExists` - Resource already exists
|
|
104
|
+
- `codes.PermissionDenied` - Authorization failure
|
|
105
|
+
- `codes.Unauthenticated` - Authentication required
|
|
106
|
+
- `codes.Internal` - Server error
|
|
107
|
+
- `codes.Unavailable` - Service unavailable
|
|
108
|
+
- `codes.DeadlineExceeded` - Timeout
|
|
109
|
+
|
|
110
|
+
### GOL.3.2.1.3: Use Interceptors for Cross-Cutting Concerns
|
|
111
|
+
|
|
112
|
+
**Rule**: Implement unary and stream interceptors for logging, auth, metrics.
|
|
113
|
+
|
|
114
|
+
**Severity**: WARNING
|
|
115
|
+
|
|
116
|
+
**Rationale**: Interceptors provide a clean way to add middleware-like functionality.
|
|
117
|
+
|
|
118
|
+
**✅ Good**:
|
|
119
|
+
```go
|
|
120
|
+
// Unary interceptor for logging
|
|
121
|
+
func loggingUnaryInterceptor(logger *slog.Logger) grpc.UnaryServerInterceptor {
|
|
122
|
+
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
|
123
|
+
start := time.Now()
|
|
124
|
+
|
|
125
|
+
resp, err := handler(ctx, req)
|
|
126
|
+
|
|
127
|
+
logger.Info("gRPC call",
|
|
128
|
+
"method", info.FullMethod,
|
|
129
|
+
"duration_ms", time.Since(start).Milliseconds(),
|
|
130
|
+
"error", err,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
return resp, err
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Stream interceptor for logging
|
|
138
|
+
func loggingStreamInterceptor(logger *slog.Logger) grpc.StreamServerInterceptor {
|
|
139
|
+
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
|
140
|
+
start := time.Now()
|
|
141
|
+
|
|
142
|
+
err := handler(srv, ss)
|
|
143
|
+
|
|
144
|
+
logger.Info("gRPC stream",
|
|
145
|
+
"method", info.FullMethod,
|
|
146
|
+
"duration_ms", time.Since(start).Milliseconds(),
|
|
147
|
+
"error", err,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
return err
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Server setup with interceptors
|
|
155
|
+
func NewServer(logger *slog.Logger) *grpc.Server {
|
|
156
|
+
return grpc.NewServer(
|
|
157
|
+
grpc.ChainUnaryInterceptor(
|
|
158
|
+
loggingUnaryInterceptor(logger),
|
|
159
|
+
authUnaryInterceptor(),
|
|
160
|
+
metricsUnaryInterceptor(),
|
|
161
|
+
),
|
|
162
|
+
grpc.ChainStreamInterceptor(
|
|
163
|
+
loggingStreamInterceptor(logger),
|
|
164
|
+
authStreamInterceptor(),
|
|
165
|
+
),
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### GOL.3.2.1.4: Implement Server-Side Streaming
|
|
171
|
+
|
|
172
|
+
**Rule**: Use server-side streaming for large result sets and real-time updates.
|
|
173
|
+
|
|
174
|
+
**Severity**: INFO
|
|
175
|
+
|
|
176
|
+
**✅ Good**:
|
|
177
|
+
```go
|
|
178
|
+
func (s *UserService) StreamUsers(req *userv1.StreamUsersRequest, stream userv1.UserService_StreamUsersServer) error {
|
|
179
|
+
ctx := stream.Context()
|
|
180
|
+
|
|
181
|
+
// Check for cancellation
|
|
182
|
+
if err := ctx.Err(); err != nil {
|
|
183
|
+
return status.Error(codes.Canceled, "stream canceled")
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Stream users in batches
|
|
187
|
+
offset := 0
|
|
188
|
+
limit := 100
|
|
189
|
+
|
|
190
|
+
for {
|
|
191
|
+
users, err := s.repo.ListUsers(ctx, offset, limit)
|
|
192
|
+
if err != nil {
|
|
193
|
+
return status.Error(codes.Internal, "failed to list users")
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if len(users) == 0 {
|
|
197
|
+
break
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for _, user := range users {
|
|
201
|
+
if err := stream.Send(&userv1.User{
|
|
202
|
+
Id: user.ID,
|
|
203
|
+
Name: user.Name,
|
|
204
|
+
Email: user.Email,
|
|
205
|
+
CreatedAt: user.CreatedAt.Unix(),
|
|
206
|
+
}); err != nil {
|
|
207
|
+
return status.Error(codes.Internal, "failed to send user")
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
offset += len(users)
|
|
212
|
+
|
|
213
|
+
if len(users) < limit {
|
|
214
|
+
break
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return nil
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### GOL.3.2.1.5: Set Appropriate Timeouts
|
|
223
|
+
|
|
224
|
+
**Rule**: Always set timeouts for gRPC calls using context.
|
|
225
|
+
|
|
226
|
+
**Severity**: ERROR
|
|
227
|
+
|
|
228
|
+
**Rationale**: Prevents hanging requests and resource exhaustion.
|
|
229
|
+
|
|
230
|
+
**✅ Good - Client**:
|
|
231
|
+
```go
|
|
232
|
+
func (c *UserClient) GetUser(ctx context.Context, id int64) (*User, error) {
|
|
233
|
+
// Set timeout for this specific call
|
|
234
|
+
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
235
|
+
defer cancel()
|
|
236
|
+
|
|
237
|
+
resp, err := c.client.GetUser(ctx, &userv1.GetUserRequest{
|
|
238
|
+
Id: id,
|
|
239
|
+
})
|
|
240
|
+
if err != nil {
|
|
241
|
+
return nil, err
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return &User{
|
|
245
|
+
ID: resp.User.Id,
|
|
246
|
+
Name: resp.User.Name,
|
|
247
|
+
Email: resp.User.Email,
|
|
248
|
+
}, nil
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## References
|
|
253
|
+
|
|
254
|
+
- [gRPC Go Quick Start](https://grpc.io/docs/languages/go/quickstart/)
|
|
255
|
+
- [gRPC Best Practices](https://grpc.io/docs/guides/performance/)
|
|
256
|
+
- [Protocol Buffers](https://developers.google.com/protocol-buffers)
|
|
257
|
+
|