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

Enable exporting spans to snowflake stage if a TruLensSnowflakeSpanExporter is provided #1708

Merged
merged 74 commits into from
Jan 17, 2025
Merged
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
929187f
move things out of app.py
sfc-gh-gtokernliang Jan 3, 2025
b4d2c84
add tests
sfc-gh-gtokernliang Jan 3, 2025
f112f38
update golden
sfc-gh-gtokernliang Jan 3, 2025
197cd0a
update app.py
sfc-gh-gtokernliang Jan 3, 2025
062d197
update golden
sfc-gh-gtokernliang Jan 3, 2025
1cc2a95
update golden
sfc-gh-gtokernliang Jan 3, 2025
dfc3fa5
move main output
sfc-gh-gtokernliang Jan 4, 2025
95f250c
PR feedback
sfc-gh-gtokernliang Jan 8, 2025
788f945
not sure why this is needed
sfc-gh-gtokernliang Jan 9, 2025
ef17076
add tests
sfc-gh-gtokernliang Jan 3, 2025
2c9d9bb
update golden
sfc-gh-gtokernliang Jan 3, 2025
85cbdc6
update test
sfc-gh-gtokernliang Jan 9, 2025
65544c9
update golden
sfc-gh-gtokernliang Jan 9, 2025
9b9644b
save
sfc-gh-gtokernliang Dec 16, 2024
02855f9
draft
sfc-gh-gtokernliang Dec 19, 2024
d9a4694
save
sfc-gh-gtokernliang Dec 20, 2024
5c939ac
add back debugger
sfc-gh-gtokernliang Dec 20, 2024
d025a07
update notebook
sfc-gh-gtokernliang Dec 20, 2024
bcd677f
fix
sfc-gh-gtokernliang Dec 21, 2024
8456019
update semcov
sfc-gh-gtokernliang Dec 21, 2024
d2d2361
remove artifacts
sfc-gh-gtokernliang Dec 24, 2024
b3ff929
remove span_types from SpanAttributes
sfc-gh-gtokernliang Dec 24, 2024
d4603b1
modified it to accept multiple tokens
sfc-gh-gtokernliang Dec 24, 2024
cbeb5a4
fix bug with multiple func calls
sfc-gh-gtokernliang Dec 24, 2024
1846dba
PR feedback
sfc-gh-gtokernliang Dec 24, 2024
eab220e
add tests
sfc-gh-gtokernliang Jan 2, 2025
093f8ad
add tests
sfc-gh-gtokernliang Jan 2, 2025
0236798
nits
sfc-gh-gtokernliang Jan 2, 2025
7d0e800
pr feedback
sfc-gh-gtokernliang Jan 3, 2025
a8e9084
update golden
sfc-gh-gtokernliang Jan 3, 2025
5d35d11
update test file
sfc-gh-gtokernliang Jan 3, 2025
af18dde
update golden
sfc-gh-gtokernliang Jan 6, 2025
f3c9e22
PR feedback
sfc-gh-gtokernliang Jan 9, 2025
e94147f
draft
sfc-gh-gtokernliang Jan 4, 2025
2a74796
remove file
sfc-gh-gtokernliang Jan 4, 2025
fd645d1
don't compress
sfc-gh-gtokernliang Jan 4, 2025
258abd2
remove print
sfc-gh-gtokernliang Jan 4, 2025
28cee08
update golden
sfc-gh-gtokernliang Jan 6, 2025
7dc4a1c
added comments
sfc-gh-gtokernliang Jan 6, 2025
d8422ad
gzip
sfc-gh-gtokernliang Jan 6, 2025
09f69ca
update
sfc-gh-gtokernliang Jan 9, 2025
ab0bb6a
update protobuf
sfc-gh-gtokernliang Jan 9, 2025
9e50f2c
Merge branch 'main' of github.com:truera/trulens into garett/SNOW-187…
sfc-gh-gtokernliang Jan 9, 2025
21f9b72
pr feedback
sfc-gh-gtokernliang Jan 9, 2025
37b6dcc
is this where I add it?
sfc-gh-gtokernliang Jan 9, 2025
e23b2fc
maybe here?
sfc-gh-gtokernliang Jan 10, 2025
af90428
undo migration
sfc-gh-gtokernliang Jan 10, 2025
0fce605
update
sfc-gh-gtokernliang Jan 10, 2025
0422373
save
sfc-gh-gtokernliang Jan 11, 2025
3083dd1
improvements
sfc-gh-gtokernliang Jan 11, 2025
18d1094
feedback
sfc-gh-gtokernliang Jan 11, 2025
910265b
remove app.py
sfc-gh-gtokernliang Jan 11, 2025
9280281
remove instruments.py
sfc-gh-gtokernliang Jan 11, 2025
6ca1f3c
remove unused
sfc-gh-gtokernliang Jan 11, 2025
a91b0eb
update
sfc-gh-gtokernliang Jan 11, 2025
b3c5eca
Merge branch 'main' of github.com:truera/trulens into garett/SNOW-187…
sfc-gh-gtokernliang Jan 11, 2025
bd3fb50
update
sfc-gh-gtokernliang Jan 11, 2025
881c68d
update
sfc-gh-gtokernliang Jan 11, 2025
5fff6fc
extract
sfc-gh-gtokernliang Jan 11, 2025
2d7b6a0
Merge branch 'garett/add-utils' of github.com:truera/trulens into gar…
sfc-gh-gtokernliang Jan 11, 2025
8bae5fb
nits
sfc-gh-gtokernliang Jan 11, 2025
c11b1c9
update golden
sfc-gh-gtokernliang Jan 12, 2025
5a55584
Merge branch 'garett/add-utils' of github.com:truera/trulens into gar…
sfc-gh-gtokernliang Jan 12, 2025
61d87a8
pr feedback
sfc-gh-gtokernliang Jan 14, 2025
8824794
Merge branch 'garett/add-utils' of github.com:truera/trulens into gar…
sfc-gh-gtokernliang Jan 14, 2025
a9f0537
pr feedback
sfc-gh-gtokernliang Jan 14, 2025
9f4c8a3
Merge branch 'main' of github.com:truera/trulens into garett/SNOW-187…
sfc-gh-gtokernliang Jan 16, 2025
f46af3c
save
sfc-gh-gtokernliang Jan 16, 2025
2903b52
draft
sfc-gh-gtokernliang Jan 17, 2025
1a5d455
comments
sfc-gh-gtokernliang Jan 17, 2025
0353258
PR feedback
sfc-gh-gtokernliang Jan 17, 2025
c28e10d
pr feedback
sfc-gh-gtokernliang Jan 17, 2025
1c1d718
update golden
sfc-gh-gtokernliang Jan 17, 2025
4e27038
PR feedback
sfc-gh-gtokernliang Jan 17, 2025
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
Prev Previous commit
Next Next commit
add tests
sfc-gh-gtokernliang committed Jan 9, 2025
commit 093f8ad9675b3f74568ac791553713d187aea62d
40 changes: 38 additions & 2 deletions src/core/trulens/experimental/otel_tracing/core/instrument.py
Original file line number Diff line number Diff line change
@@ -21,9 +21,46 @@
logger = logging.getLogger(__name__)


VALID_ATTR_VALUE_TYPES = (bool, str, int, float)
"""
Per the OTEL [documentation](https://opentelemetry.io/docs/specs/otel/common/#attribute),
valid attribute value types are either:
- A primitive type: string, boolean, double precision floating point (IEEE 754-1985) or signed 64 bit integer.
- An array of primitive type values. The array MUST be homogeneous, i.e., it MUST NOT contain values of different types.
"""


def validate_value_for_attribute(value):
"""
Ensure that value is a valid attribute value type, and coerce it to a string if it is not.

This is helpful for lists/etc because if any single value is not a valid attribute value type, the entire list
will not be added as a span attribute.
"""
arg_type = type(value)

# Coerge the argument to a string if it is not a valid attribute value type.
if arg_type not in VALID_ATTR_VALUE_TYPES:
return str(value)

return value


def validate_list_of_values_for_attribute(arguments: list):
"""
Ensure that all values in a list are valid attribute value types, and coerce them to strings if they are not.
"""
return list(map(validate_value_for_attribute, arguments))


def validate_selector_name(attributes: Dict[str, Any]) -> Dict[str, Any]:
"""
Utility function to validate the selector name in the attributes.

It does the following:
1. Ensure that the selector name is a string.
2. Ensure that the selector name is keyed with either the trulens/non-trulens key variations.
3. Ensure that the selector name is not set in both the trulens and non-trulens key variations.
"""

result = attributes.copy()
@@ -62,8 +99,7 @@ def validate_attributes(attributes: Dict[str, Any]) -> Dict[str, Any]:
]):
raise ValueError("Attributes must be a dictionary with string keys.")
return validate_selector_name(attributes)
# TODO: validate OTEL attributes.
# TODO: validate span type attributes.
# TODO: validate Span type attributes.


def instrument(
57 changes: 57 additions & 0 deletions tests/unit/test_otel_instrument.py
Original file line number Diff line number Diff line change
@@ -12,9 +12,15 @@
from trulens.core.session import TruSession
from trulens.experimental.otel_tracing.core.init import init
from trulens.experimental.otel_tracing.core.instrument import instrument
from trulens.experimental.otel_tracing.core.instrument import (
validate_list_of_values_for_attribute,
)
from trulens.experimental.otel_tracing.core.instrument import (
validate_selector_name,
)
from trulens.experimental.otel_tracing.core.instrument import (
validate_value_for_attribute,
)
from trulens.otel.semconv.trace import SpanAttributes

from tests.test import TruTestCase
@@ -187,6 +193,57 @@ def test_validate_selector_name(self):
{SpanAttributes.SELECTOR_NAME_KEY: "name"},
)

def test_validate_value_for_attribute(self):
with self.subTest("None"):
self.assertEqual(validate_value_for_attribute(None), "None")

with self.subTest("number"):
self.assertEqual(
validate_value_for_attribute(42),
42,
)

with self.subTest("string"):
self.assertEqual(
validate_value_for_attribute("31"),
"31",
)

with self.subTest("bool"):
self.assertFalse(
validate_value_for_attribute(False),
)

with self.subTest("float"):
self.assertEqual(
validate_value_for_attribute(3.14),
3.14,
)

with self.subTest("dict"):
self.assertEqual(
validate_value_for_attribute({"key": "value"}),
"{'key': 'value'}",
)

def test_validate_list_of_values_for_attribute(self):
with self.subTest("list of primitives"):
self.assertEqual(
validate_list_of_values_for_attribute([1, "2", True]),
[1, "2", True],
)

with self.subTest("list of primitives and non-primitives"):
self.assertEqual(
validate_list_of_values_for_attribute([
1,
"2",
True,
{"key": "value"},
]),
[1, "2", True, "{'key': 'value'}"],
)


if __name__ == "__main__":
main()