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

DO NOT MERGE - demonstrating failed copilot agent run #1484

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
117 changes: 117 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# OpenTelemetry Code Analysis & Instrumentation

Analyze code and provide specific instrumentation recommendations optimized for Honeycomb, with a preference for using OpenTelemetry tracing if possible.

Support direct instructions, like "instrument this file" or "add tracing to this function."

## Rules to follow

Ignore metrics code, if it exists, for now.

Focus on enhancing any existing logs, then suggest span instrumentation if requested.

If there are no existing logging calls, suggest using OpenTelemetry spans instead, unless explicitly asked to add logs.

## Logging Enhancements

If code has logging, recommend improvements to:

1. Add proper log levels for different types of operations:
```
# Instead of:
print("Processing order")
logger.info(f"Order {id} status: {status}")

# Better as:
logger.info("Starting order processing", {"app.order_id": id})
logger.error("Order processing failed", {"app.order_id": id, "app.error": str(e)})
```

2. Convert print statements to structured logs:
```
# Instead of:
print(f"Processing order {id} for customer {customer}")

# Better as:
logger.info("Processing order", {
"app.order_id": id,
"app.customer_id": customer.id,
"app.items_count": len(items)
})
```

3. Consolidate related logs into single, rich events:
```
# Instead of multiple logs:
logger.info(f"Processing order {id}")
items = process_order(id)
logger.info(f"Found {len(items)} items")
discount = apply_discount(items)
logger.info(f"Applied discount: {discount}")

# Better as one structured log:
logger.info("Processing order", {
"app.order_id": id,
"app.items_count": len(items),
"app.discount_applied": discount,
"app.customer_tier": customer.tier
})
```

4. Capture high-cardinality data and data useful for debugging from function parameters in structured fields, such as:
- `app.user_id`
- `app.request_id`
- `app.order_id`, `app.product_id`, etc.
- Operation parameters
- State information

In particular, especially focus on consolidating logs that can be combined into a single, rich event.

## Span Instrumentation (If Requested)

If instrumenting iwth spans, recommend instrumentation that:

1. Adds important high-cardinality data, request context, and data useful for debugging from function parameters to the current span:
```
current_span.set_attributes({
"app.customer_id": request.customer_id,
"app.order_type": request.type,
"app.items_count": len(request.items)
})
```

2. Creates spans for meaningful operations:
```
with span("create_order") as order_span:
order = create_order(request)
order_span.set_attributes({
"app.order_id": order.id,
"app.total_amount": order.total
})
```

3. Handles errors properly:
```
try:
# operation code
catch Error as e:
span.set_attributes({
"error": true,
"error.type": type(e),
"error.message": str(e)
})
raise
```

## Additional considerations

Always use well-defined, specific, and namespaced keys for structured logs and span attributes.

Consider deeply if clarification is needed on:

- The purpose or context of specific code sections
- Which operations are most important to instrument
- Whether to focus on logging improvements or span creation, especially if both are present
- The meaning of domain-specific terms or variables

Ask for more information before providing recommendations if necessary.
16 changes: 11 additions & 5 deletions cmd/refinery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ var BuildID string
var version string

type graphLogger struct {
logger logger.Logger
}

// TODO: make this log properly
func (g graphLogger) Debugf(format string, v ...interface{}) {
fmt.Printf(format, v...)
fmt.Println()
// Initialize the graph logger
func newGraphLogger(l logger.Logger) *graphLogger {
return &graphLogger{logger: l}
}

func (g *graphLogger) Debugf(format string, v ...interface{}) {
if g.logger != nil {
g.logger.Debug().WithField("component", "graph").Logf(format, v...)
}
}

func main() {
Expand Down Expand Up @@ -252,7 +258,7 @@ func main() {
// we need to include all the metrics types so we can inject them in case they're needed
var g inject.Graph
if opts.Debug {
g.Logger = graphLogger{}
g.Logger = newGraphLogger(lgr)
}
objects := []*inject.Object{
{Value: c},
Expand Down
Loading