Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion packages/uipath-platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-platform"
version = "0.3.12"
version = "0.3.13"
description = "HTTP client library for programmatic access to UiPath Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import json
import logging
import mimetypes
import os
import uuid
from dataclasses import dataclass, field
Expand All @@ -14,7 +15,7 @@
from opentelemetry import trace
from opentelemetry.sdk.trace import ReadableSpan, Span, SpanProcessor
from opentelemetry.trace import StatusCode, format_span_id
from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, ConfigDict, Field, model_validator
from uipath.core.serialization import serialize_json

from uipath.platform.constants import (
Expand Down Expand Up @@ -223,6 +224,15 @@ class SpanAttachment(BaseModel):
default=AttachmentDirection.NONE, alias="direction"
)

@model_validator(mode="after")
def _default_blank_mime_type(self) -> "SpanAttachment":
# The traces API rejects the whole span when an attachment has no MIME type.
if not self.mime_type.strip():
self.mime_type = (
mimetypes.guess_type(self.file_name)[0] or "application/octet-stream"
)
return self


@dataclass
class UiPathSpan:
Expand Down
56 changes: 56 additions & 0 deletions packages/uipath-platform/tests/services/test_span_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from uipath.platform.common._span_utils import (
_SOURCE_BY_INT,
ExecutionType,
SpanAttachment,
SpanSource,
SpanStatus,
VerbosityLevel,
Expand Down Expand Up @@ -1253,3 +1254,58 @@ def test_ended_span_keeps_real_end_time(self) -> None:

assert uipath_span.end_time is not None
assert uipath_span.to_dict()["EndTime"] == uipath_span.end_time


class TestSpanAttachmentMimeType:
@pytest.mark.parametrize(
("file_name", "mime_type", "expected"),
[
("report.pdf", "", "application/pdf"),
("client.ovpn", "", "application/octet-stream"),
("client.ovpn", " ", "application/octet-stream"),
("", "", "application/octet-stream"),
("client.ovpn", "text/plain", "text/plain"),
],
)
def test_blank_mime_type_is_replaced(self, file_name, mime_type, expected):
attachment = SpanAttachment(
id="0f877427-f8ab-457e-1df3-08df4715cc29",
file_name=file_name,
mime_type=mime_type,
)

assert attachment.mime_type == expected

def test_span_with_untyped_attachment_serializes_a_mime_type(self):
mock_span = Mock(spec=OTelSpan)
mock_span.get_span_context.return_value = SpanContext(
trace_id=0x123456789ABCDEF0123456789ABCDEF0,
span_id=0x0123456789ABCDEF,
is_remote=False,
)
mock_span.name = "Agent run - Agent"
mock_span.parent = None
mock_span.status.status_code = StatusCode.OK
mock_span.attributes = {
"attachments": json.dumps(
[
{
"id": "81584504-38b3-406b-1df4-08df4715cc29",
"fileName": "test-client-1.ovpn",
"mimeType": "",
"provider": 0,
"direction": 1,
}
]
)
}
mock_span.events = []
mock_span.links = []
mock_span.start_time = int(datetime.now().timestamp() * 1e9)
mock_span.end_time = mock_span.start_time + 1_000_000

payload = _SpanUtils.otel_span_to_uipath_span(mock_span).to_dict()

assert [att["MimeType"] for att in payload["Attachments"]] == [
"application/octet-stream"
]
2 changes: 1 addition & 1 deletion packages/uipath-platform/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/uipath/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading