Skip to content

Commit 56fbab3

Browse files
authored
Update documentation
1 parent 3732a29 commit 56fbab3

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

cli/azd/docs/extension-framework.md

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -334,42 +334,6 @@ The build process automatically creates binaries for multiple platforms and arch
334334
> [!NOTE]
335335
> Build times may vary depending on your hardware and extension complexity.
336336
337-
### Distributed Tracing
338-
339-
`azd` uses OpenTelemetry and W3C Trace Context for distributed tracing. To ensure your extension's operations are correctly correlated with the parent `azd` process, you must hydrate the context in your extension's entry point.
340-
341-
**Update `main.go`:**
342-
343-
```go
344-
import (
345-
"context"
346-
"os"
347-
"github.com/azure/azure-dev/cli/azd/pkg/azdext"
348-
)
349-
350-
func main() {
351-
ctx := context.Background()
352-
353-
// Hydrate context with traceparent from environment if present
354-
// This ensures the extension process participates in the active trace
355-
if traceparent := os.Getenv("TRACEPARENT"); traceparent != "" {
356-
ctx = azdext.ContextFromTraceParent(ctx, traceparent)
357-
}
358-
359-
rootCmd := cmd.NewRootCommand()
360-
361-
if err := rootCmd.ExecuteContext(ctx); err != nil {
362-
// Handle error
363-
}
364-
}
365-
```
366-
367-
The `ExtensionHost` automatically handles trace propagation for all gRPC communication:
368-
1. **Outgoing**: Traces are injected into messages sent back to `azd` core.
369-
2. **Incoming**: Traces from `azd` core are extracted and injected into the `context.Context` passed to your handlers.
370-
371-
This ensures that calls to Azure SDKs (which support `TRACEPARENT`) within your handlers will automatically be correlated.
372-
373337
### Developer Extension
374338

375339
The easiest way to get started building extensions is to install the `azd` Developer extension.
@@ -1127,6 +1091,38 @@ if err := host.Run(ctx); err != nil {
11271091

11281092
```
11291093

1094+
### Distributed Tracing
1095+
1096+
`azd` uses OpenTelemetry and W3C Trace Context for distributed tracing.
1097+
1098+
#### Handlers (Service Targets, Framework Services, Event Handlers)
1099+
1100+
Trace context is **automatically propagated** through gRPC messages. The `context.Context` passed to your handlers already contains the trace context from `azd`—no additional setup is required.
1101+
1102+
To correlate Azure SDK calls with the parent trace, add the correlation policy to your client options:
1103+
1104+
```go
1105+
import "github.com/azure/azure-dev/cli/azd/pkg/azsdk"
1106+
1107+
clientOptions := &policy.ClientOptions{
1108+
PerCallPolicies: []policy.Policy{
1109+
azsdk.NewMsCorrelationPolicy(),
1110+
},
1111+
}
1112+
```
1113+
1114+
#### Custom Commands
1115+
1116+
For custom extension commands (not using `ExtensionHost`), hydrate the context from the `TRACEPARENT` environment variable:
1117+
1118+
```go
1119+
if traceparent := os.Getenv("TRACEPARENT"); traceparent != "" {
1120+
ctx = azdext.ContextFromTraceParent(ctx, traceparent)
1121+
}
1122+
```
1123+
1124+
`azd` sets this variable when launching extension processes.
1125+
11301126
## Developer Artifacts
11311127

11321128
`azd` leverages gRPC for the communication protocol between Core `azd` and extensions. gRPC client & server components are automatically generated from profile files.

0 commit comments

Comments
 (0)