-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bef033
commit bef939f
Showing
3 changed files
with
208 additions
and
37 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
python/openinference-instrumentation/examples/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jupyter | ||
opentelemetry-sdk | ||
opentelemetry-exporter-otlp | ||
openinference-semantic-conventions |
108 changes: 108 additions & 0 deletions
108
python/openinference-instrumentation/examples/tracer.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import json\n", | ||
"\n", | ||
"from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\n", | ||
"from opentelemetry.sdk.resources import Resource\n", | ||
"from opentelemetry.sdk.trace import TracerProvider\n", | ||
"from opentelemetry.sdk.trace.export import SimpleSpanProcessor\n", | ||
"from opentelemetry.trace import Status, StatusCode\n", | ||
"\n", | ||
"from openinference.instrumentation import OITracerProvider, TraceConfig\n", | ||
"from openinference.semconv.resource import ResourceAttributes" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"endpoint = \"http://127.0.0.1:6006/v1/traces\"\n", | ||
"resource = Resource(attributes={ResourceAttributes.PROJECT_NAME: \"openinference-tracer\"})\n", | ||
"tracer_provider = OITracerProvider(wrapped=TracerProvider(resource=resource), config=TraceConfig())\n", | ||
"tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))\n", | ||
"tracer = tracer_provider.get_tracer(__name__)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Chains" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Context manager" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"with tracer.start_as_current_chain_span(\n", | ||
" \"plain-text-input-plain-text-output\",\n", | ||
" kind=\"chain\",\n", | ||
") as span:\n", | ||
" span.set_input(\"input\")\n", | ||
" span.set_output(\"output\")\n", | ||
" span.set_status(Status(StatusCode.OK))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"with tracer.start_as_current_chain_span(\n", | ||
" \"json-input-json-output\",\n", | ||
") as span:\n", | ||
" span.set_output(\n", | ||
" json.dumps({\"output-key\": \"output-value\"}),\n", | ||
" mime_type=\"application/json\",\n", | ||
" )\n", | ||
" span.set_status(Status(StatusCode.OK))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.20" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters