-
Notifications
You must be signed in to change notification settings - Fork 197
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
d5ce738
commit 712f97b
Showing
4 changed files
with
226 additions
and
136 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,126 +1,147 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# !pip install opentelemetry-api\n", | ||
"# !pip install opentelemetry-sdk" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pathlib import Path\n", | ||
"import sys\n", | ||
"\n", | ||
"# Add base dir to path to be able to access test folder.\n", | ||
"base_dir = Path().cwd().parent.parent.resolve()\n", | ||
"if str(base_dir) not in sys.path:\n", | ||
" print(f\"Adding {base_dir} to sys.path\")\n", | ||
" sys.path.append(str(base_dir))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from trulens.experimental.otel_tracing.core.instrument import instrument\n", | ||
"\n", | ||
"\n", | ||
"class TestApp:\n", | ||
" @instrument()\n", | ||
" def respond_to_query(self, query: str) -> str:\n", | ||
" return f\"answer: {self.nested(query)}\"\n", | ||
"\n", | ||
" @instrument(attributes={\"nested_attr1\": \"value1\"})\n", | ||
" def nested(self, query: str) -> str:\n", | ||
" return f\"nested: {self.nested2(query)}\"\n", | ||
"\n", | ||
" @instrument(\n", | ||
" attributes=lambda ret, *args, **kwargs: {\n", | ||
" \"nested2_ret\": ret,\n", | ||
" \"nested2_args[0]\": args[0],\n", | ||
" }\n", | ||
" )\n", | ||
" def nested2(self, query: str) -> str:\n", | ||
" return f\"nested2: {query}\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"import dotenv\n", | ||
"from trulens.connectors.snowflake import SnowflakeConnector\n", | ||
"from trulens.core.session import TruSession\n", | ||
"from trulens.experimental.otel_tracing.core.init import init\n", | ||
"\n", | ||
"dotenv.load_dotenv()\n", | ||
"\n", | ||
"connection_params = {\n", | ||
" \"account\": os.environ[\"SNOWFLAKE_ACCOUNT\"],\n", | ||
" \"user\": os.environ[\"SNOWFLAKE_USER\"],\n", | ||
" \"password\": os.environ[\"SNOWFLAKE_USER_PASSWORD\"],\n", | ||
" \"database\": os.environ[\"SNOWFLAKE_DATABASE\"],\n", | ||
" \"schema\": os.environ[\"SNOWFLAKE_SCHEMA\"],\n", | ||
" \"warehouse\": os.environ[\"SNOWFLAKE_WAREHOUSE\"],\n", | ||
" \"role\": os.environ[\"SNOWFLAKE_ROLE\"],\n", | ||
"}\n", | ||
"\n", | ||
"connector = SnowflakeConnector(\n", | ||
" **connection_params, database_redact_keys=True, database_args=None\n", | ||
")\n", | ||
"session = TruSession(connector=connector)\n", | ||
"session.reset_database()\n", | ||
"init(session, debug=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from trulens.apps.custom import TruCustomApp\n", | ||
"\n", | ||
"test_app = TestApp()\n", | ||
"custom_app = TruCustomApp(test_app)\n", | ||
"\n", | ||
"with custom_app as recording:\n", | ||
" test_app.respond_to_query(\"test\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "trulens", | ||
"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" | ||
} | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# !pip install opentelemetry-api\n", | ||
"# !pip install opentelemetry-sdk" | ||
] | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pathlib import Path\n", | ||
"import sys\n", | ||
"\n", | ||
"# Add base dir to path to be able to access test folder.\n", | ||
"base_dir = Path().cwd().parent.parent.resolve()\n", | ||
"if str(base_dir) not in sys.path:\n", | ||
" print(f\"Adding {base_dir} to sys.path\")\n", | ||
" sys.path.append(str(base_dir))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import logging\n", | ||
"\n", | ||
"root = logging.getLogger()\n", | ||
"root.setLevel(logging.DEBUG)\n", | ||
"handler = logging.StreamHandler(sys.stdout)\n", | ||
"handler.setLevel(logging.DEBUG)\n", | ||
"handler.addFilter(logging.Filter(\"trulens\"))\n", | ||
"formatter = logging.Formatter(\n", | ||
" \"%(asctime)s - %(name)s - %(levelname)s - %(message)s\"\n", | ||
")\n", | ||
"handler.setFormatter(formatter)\n", | ||
"root.addHandler(handler)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from trulens.experimental.otel_tracing.core.instrument import instrument\n", | ||
"\n", | ||
"\n", | ||
"class TestApp:\n", | ||
" @instrument()\n", | ||
" def respond_to_query(self, query: str) -> str:\n", | ||
" return f\"answer: {self.nested(query)}\"\n", | ||
"\n", | ||
" @instrument(attributes={\"nested_attr1\": \"value1\"})\n", | ||
" def nested(self, query: str) -> str:\n", | ||
" return f\"nested: {self.nested2(query)}\"\n", | ||
"\n", | ||
" @instrument(\n", | ||
" attributes=lambda ret, *args, **kwargs: {\n", | ||
" \"nested2_ret\": ret,\n", | ||
" \"nested2_args[0]\": args[0],\n", | ||
" }\n", | ||
" )\n", | ||
" def nested2(self, query: str) -> str:\n", | ||
" return f\"nested2: {query}\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"import dotenv\n", | ||
"from trulens.connectors.snowflake import SnowflakeConnector\n", | ||
"from trulens.core.session import TruSession\n", | ||
"from trulens.experimental.otel_tracing.core.init import init\n", | ||
"\n", | ||
"dotenv.load_dotenv()\n", | ||
"\n", | ||
"connection_params = {\n", | ||
" \"account\": os.environ[\"SNOWFLAKE_ACCOUNT\"],\n", | ||
" \"user\": os.environ[\"SNOWFLAKE_USER\"],\n", | ||
" \"password\": os.environ[\"SNOWFLAKE_USER_PASSWORD\"],\n", | ||
" \"database\": os.environ[\"SNOWFLAKE_DATABASE\"],\n", | ||
" \"schema\": os.environ[\"SNOWFLAKE_SCHEMA\"],\n", | ||
" \"warehouse\": os.environ[\"SNOWFLAKE_WAREHOUSE\"],\n", | ||
" \"role\": os.environ[\"SNOWFLAKE_ROLE\"],\n", | ||
"}\n", | ||
"\n", | ||
"connector = SnowflakeConnector(\n", | ||
" **connection_params, database_redact_keys=True, database_args=None\n", | ||
")\n", | ||
"session = TruSession(connector=connector)\n", | ||
"session.experimental_enable_feature(\"otel_tracing\")\n", | ||
"session.reset_database()\n", | ||
"init(session, debug=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from trulens.apps.custom import TruCustomApp\n", | ||
"\n", | ||
"test_app = TestApp()\n", | ||
"custom_app = TruCustomApp(test_app)\n", | ||
"\n", | ||
"with custom_app as recording:\n", | ||
" test_app.respond_to_query(\"test\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "trulens", | ||
"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" | ||
} | ||
}, | ||
"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
Oops, something went wrong.