Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
codefromthecrypt committed Sep 19, 2024
1 parent d7596b0 commit 5101754
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
5 changes: 0 additions & 5 deletions .otel.env

This file was deleted.

5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,12 @@ of the underlying HTTP requests. For example, a 404 could be indicative of an in
First, ensure you have an OpenTelemetry compatible collector listening on port 4318, such as [otel-tui][otel-tui].

```bash
brew install ymtdzzz/tap/otel-tui
otel-tui
docker run --rm -it --name otel-tui -p 4318:4318 ymtdzzz/otel-tui
```

Then, start goose like this:
```bash
uv run dotenv -f ./.otel.env run -- opentelemetry-instrument goose session start
uv run opentelemetry-instrument --service_name goose --exporter_otlp_protocol http/protobuf goose session start
# or `just otel-goose session start`
```

Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ docs:
cd docs && uv sync && uv run mkdocs serve

otel-goose *FLAGS:
uv run dotenv -f ./.otel.env run -- opentelemetry-instrument goose {{FLAGS}}
uv run opentelemetry-instrument --service_name goose --exporter_otlp_protocol http/protobuf goose {{FLAGS}}
25 changes: 16 additions & 9 deletions src/goose/cli/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ def __init__(
name: Optional[str] = None,
profile: Optional[str] = None,
plan: Optional[dict] = None,
tracer: trace.Tracer = trace.get_tracer(__name__),
tracer: trace.Tracer = trace.get_tracer("goose"),
**kwargs: Dict[str, Any],
) -> None:
self.name = name
self.status_indicator = Status("", spinner="dots")
self.notifier = SessionNotifier(self.status_indicator)

# Set the tracer as a field in session, as opposed to a module variable
# so that tests can swap this out and safely run in parallel.
self.tracer = tracer

self.exchange = build_exchange(profile=load_profile(profile), notifier=self.notifier)
Expand Down Expand Up @@ -154,20 +157,24 @@ def run(self) -> None:
"""
message = self.process_first_message()
while message: # Loop until no input (empty string).
# Start a span with the default tracer. This is present with opentelemetry-instrument
with self.tracer.start_as_current_span(message.role) as span:
span.set_attribute("goose.role", message.role)
span.set_attribute("goose.id", message.id)
# For starters, only add to the trace the first text content
first_content = message.content[0] if message.content else None
if isinstance(first_content, Text):
span.set_attribute("goose.text", first_content.text)
span_attributes = {
"goose.role": message.role,
"goose.id": message.id,
}

# For starters, only add to the trace the first text content
first_content = message.content[0] if message.content else None
if isinstance(first_content, Text):
span_attributes["goose.text"] = first_content.text

with self.tracer.start_as_current_span(message.role, attributes=span_attributes) as span:
self.notifier.start()
try:
self.exchange.add(message)
self.reply() # Process the user message.
except KeyboardInterrupt:
# TODO: should we make interrupting an error? If not, how should we mark this?
# span as it was interrupted?
span.set_status(OtelStatus(OtelStatusCode.ERROR, "KeyboardInterrupt"))
self.interrupt_reply()
except Exception as e:
Expand Down

0 comments on commit 5101754

Please sign in to comment.