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

Feat/observability support #798

Merged
merged 29 commits into from
Oct 18, 2024
Merged

Feat/observability support #798

merged 29 commits into from
Oct 18, 2024

Conversation

Pouyanpi
Copy link
Collaborator

@Pouyanpi Pouyanpi commented Oct 10, 2024

Description

Implements a tracing module to assign a trace id to every incoming request and enable detailed tracing of every rail/action/LLM call that is triggered behind the scenes. Can export the traces to different providers like OpenTelemetry, etc.

Example Usage

Consider following config.yml

models:
  - type: main
    engine: openai
    model: gpt-3.5-turbo-instruct

tracing:
  enabled: true
  adapters:
    - name: OpenTelemetry
      service_name: "nemo_guardrails_service"
      exporter: "console"
      resource_attributes:
        env: "production"
    - name: FileSystem
      filepath: "./traces/traces.jsonl"
    

Now you can also use zipkin as expoerter.

To do so:

pip install opentelemetry-exporter-zipkin
docker run -d -p 9411:9411 openzipkin/zipkin

and set the exporter to zipkin in config.yml :

tracing:
  enabled: true
  adapters:
    - name: OpenTelemetry
      service_name: "nemo_guardrails_service"
      exporter: "zipkin"
      resource_attributes:
        env: "production"
   

Note:

Test Coverage

File Statements Missed Coverage Missing Lines
tests/test_tracing.py 49 1 98% 128
tests/test_tracing_adapters_filesystem.py 31 0 100% -
tests/test_tracing_adapters_opentelemetry.py 69 5 93% 146-152, 186

Checklist

  • I've read the CONTRIBUTING guidelines.
  • I've updated the documentation if applicable.
  • I've added tests if applicable.
  • opentelemetry dependencies in pyproject.toml - @drazvan

@Pouyanpi Pouyanpi self-assigned this Oct 10, 2024
@Pouyanpi Pouyanpi requested a review from drazvan October 10, 2024 13:43
@Pouyanpi Pouyanpi force-pushed the feat/observability-support branch from 88001b1 to 87d71d6 Compare October 10, 2024 15:22
Copy link
Collaborator

@drazvan drazvan left a comment

Choose a reason for hiding this comment

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

Looks good 👍. After fixing the issues, good to merge.

nemoguardrails/rails/llm/config.py Outdated Show resolved Hide resolved
nemoguardrails/rails/llm/llmrails.py Outdated Show resolved Hide resolved
nemoguardrails/tracing/adapters/filesystem.py Outdated Show resolved Hide resolved
nemoguardrails/rails/llm/llmrails.py Show resolved Hide resolved
@Pouyanpi Pouyanpi force-pushed the feat/observability-support branch from 2d80944 to aca147d Compare October 14, 2024 16:54
@Pouyanpi Pouyanpi force-pushed the feat/observability-support branch from aca147d to 6c8d080 Compare October 16, 2024 09:03
@Pouyanpi Pouyanpi force-pushed the feat/observability-support branch from 6c8d080 to a91055a Compare October 16, 2024 09:12
@Pouyanpi
Copy link
Collaborator Author

@drazvan the changes are done. Currently tracing dependencies are added to pyproject.toml and using defered import like similar situations in the codebase would clutter the adapters.opentelmetry module. Dependency req is included in the documentation.

@Pouyanpi Pouyanpi requested a review from drazvan October 16, 2024 09:12
@Pouyanpi Pouyanpi marked this pull request as ready for review October 16, 2024 09:13
@Pouyanpi Pouyanpi force-pushed the feat/observability-support branch from d27e962 to 13e3f11 Compare October 16, 2024 12:33
@Pouyanpi Pouyanpi added this to the v0.11.0 milestone Oct 16, 2024
Copy link
Collaborator

@drazvan drazvan left a comment

Choose a reason for hiding this comment

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

Approving to unblock. Will review in more detail next week.

@Pouyanpi Pouyanpi merged commit c038b08 into develop Oct 18, 2024
4 checks passed
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.

2 participants