diff --git a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/__init__.py b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/__init__.py index 436286111..7a6076666 100644 --- a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/__init__.py +++ b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/__init__.py @@ -32,10 +32,33 @@ def _set_span_attribute(span, name, value): return +def _set_client_attributes(span, instance): + if not span.is_recording(): + return + + if not is_openai_v1(): + return + + try: + client = instance._client # pylint: disable=protected-access + if isinstance(client, (openai.AsyncOpenAI, openai.OpenAI)): + _set_span_attribute(span, OPENAI_API_BASE, str(client.base_url)) + if isinstance(client, (openai.AsyncAzureOpenAI, openai.AzureOpenAI)): + _set_span_attribute(span, OPENAI_API_VERSION, client._api_version) # pylint: disable=protected-access + + except Exception as ex: # pylint: disable=broad-except + logger.warning( + "Failed to set api attributes for openai v1 span, error: %s", str(ex) + ) + + def _set_api_attributes(span): if not span.is_recording(): return + if is_openai_v1(): + return + try: base_url = openai.base_url if hasattr(openai, "base_url") else openai.api_base diff --git a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py index 0022114e8..49dbf3bab 100644 --- a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py +++ b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py @@ -8,6 +8,7 @@ from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY from opentelemetry.instrumentation.openai.utils import _with_tracer_wrapper from opentelemetry.instrumentation.openai.shared import ( + _set_client_attributes, _set_request_attributes, _set_span_attribute, _set_functions_attributes, @@ -39,7 +40,7 @@ def chat_wrapper(tracer, wrapped, instance, args, kwargs): attributes={SpanAttributes.LLM_REQUEST_TYPE: LLM_REQUEST_TYPE.value}, ) - _handle_request(span, kwargs) + _handle_request(span, kwargs, instance) response = wrapped(*args, **kwargs) if is_streaming_response(response): @@ -62,7 +63,7 @@ async def achat_wrapper(tracer, wrapped, instance, args, kwargs): kind=SpanKind.CLIENT, attributes={SpanAttributes.LLM_REQUEST_TYPE: LLM_REQUEST_TYPE.value}, ) - _handle_request(span, kwargs) + _handle_request(span, kwargs, instance) response = await wrapped(*args, **kwargs) if is_streaming_response(response): @@ -75,8 +76,9 @@ async def achat_wrapper(tracer, wrapped, instance, args, kwargs): return response -def _handle_request(span, kwargs): +def _handle_request(span, kwargs, instance): _set_request_attributes(span, kwargs) + _set_client_attributes(span, instance) if should_send_prompts(): _set_prompts(span, kwargs.get("messages")) _set_functions_attributes(span, kwargs.get("functions")) diff --git a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/completion_wrappers.py b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/completion_wrappers.py index 9e0478b0c..c5fc2ef0c 100644 --- a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/completion_wrappers.py +++ b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/completion_wrappers.py @@ -7,6 +7,7 @@ from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY from opentelemetry.instrumentation.openai.utils import _with_tracer_wrapper from opentelemetry.instrumentation.openai.shared import ( + _set_client_attributes, _set_request_attributes, _set_span_attribute, _set_functions_attributes, @@ -39,7 +40,7 @@ def completion_wrapper(tracer, wrapped, instance, args, kwargs): attributes={SpanAttributes.LLM_REQUEST_TYPE: LLM_REQUEST_TYPE.value}, ) - _handle_request(span, kwargs) + _handle_request(span, kwargs, instance) response = wrapped(*args, **kwargs) if is_streaming_response(response): @@ -63,7 +64,7 @@ async def acompletion_wrapper(tracer, wrapped, instance, args, kwargs): attributes={SpanAttributes.LLM_REQUEST_TYPE: LLM_REQUEST_TYPE.value}, ) - _handle_request(span, kwargs) + _handle_request(span, kwargs, instance) response = await wrapped(*args, **kwargs) if is_streaming_response(response): @@ -76,11 +77,12 @@ async def acompletion_wrapper(tracer, wrapped, instance, args, kwargs): return response -def _handle_request(span, kwargs): +def _handle_request(span, kwargs, instance): _set_request_attributes(span, kwargs) if should_send_prompts(): _set_prompts(span, kwargs.get("prompt")) _set_functions_attributes(span, kwargs.get("functions")) + _set_client_attributes(span, instance) def _handle_response(response, span): diff --git a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py index ca5e0d612..81c01183b 100644 --- a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py +++ b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py @@ -10,6 +10,7 @@ start_as_current_span_async, ) from opentelemetry.instrumentation.openai.shared import ( + _set_client_attributes, _set_request_attributes, _set_span_attribute, _set_response_attributes, @@ -37,7 +38,7 @@ def embeddings_wrapper(tracer, wrapped, instance, args, kwargs): kind=SpanKind.CLIENT, attributes={SpanAttributes.LLM_REQUEST_TYPE: LLM_REQUEST_TYPE.value}, ) as span: - _handle_request(span, kwargs) + _handle_request(span, kwargs, instance) response = wrapped(*args, **kwargs) _handle_response(response, span) @@ -55,17 +56,18 @@ async def aembeddings_wrapper(tracer, wrapped, instance, args, kwargs): kind=SpanKind.CLIENT, attributes={SpanAttributes.LLM_REQUEST_TYPE: LLM_REQUEST_TYPE.value}, ) as span: - _handle_request(span, kwargs) + _handle_request(span, kwargs, instance) response = await wrapped(*args, **kwargs) _handle_response(response, span) return response -def _handle_request(span, kwargs): +def _handle_request(span, kwargs, instance): _set_request_attributes(span, kwargs) if should_send_prompts(): _set_prompts(span, kwargs.get("input")) + _set_client_attributes(span, instance) def _handle_response(response, span): diff --git a/packages/opentelemetry-instrumentation-openai/tests/cassettes/test_embeddings/test_azure_openai_embeddings.yaml b/packages/opentelemetry-instrumentation-openai/tests/cassettes/test_embeddings/test_azure_openai_embeddings.yaml new file mode 100644 index 000000000..e4b5d98c5 --- /dev/null +++ b/packages/opentelemetry-instrumentation-openai/tests/cassettes/test_embeddings/test_azure_openai_embeddings.yaml @@ -0,0 +1,457 @@ +interactions: +- request: + body: '{"input": "Tell me a joke about opentelemetry", "model": "embedding"}' + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + api-key: + - redacted + connection: + - keep-alive + content-length: + - '69' + content-type: + - application/json + host: + - redacted.openai.azure.com + user-agent: + - AzureOpenAI/Python 1.12.0 + x-stainless-arch: + - x64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 1.12.0 + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.11.1 + method: POST + uri: https://redacted.openai.azure.com/openai/deployments/embedding/embeddings?api-version=2023-07-01-preview + response: + body: + string: "{\n \"object\": \"list\",\n \"data\": [\n {\n \"object\": + \"embedding\",\n \"index\": 0,\n \"embedding\": [\n 0.025223017,\n + \ -0.0050446033,\n -0.0033448678,\n -0.014584258,\n 0.013393562,\n + \ 0.030746715,\n -0.014457438,\n 0.017627928,\n -0.022263892,\n + \ -0.011667406,\n 0.035481315,\n 0.0024113343,\n -0.0057702935,\n + \ -0.033283107,\n 0.0035949843,\n 0.010420347,\n 0.02605439,\n + \ -0.015739726,\n 0.015443813,\n -0.020474326,\n -0.020051593,\n + \ -0.0016706726,\n -0.007559859,\n 0.026491212,\n -0.0058407485,\n + \ -0.009102832,\n 0.015739726,\n -0.010251254,\n 0.0038750444,\n + \ -0.009236696,\n 0.02580075,\n 0.01237196,\n -0.031676725,\n + \ -0.0028904309,\n -0.015373358,\n -0.013062422,\n 0.003432937,\n + \ -0.005724497,\n 0.026970308,\n -0.00038222029,\n 0.00602041,\n + \ 0.016754283,\n 0.017684294,\n -0.026040299,\n -0.019135674,\n + \ 0.022461167,\n 0.0016028592,\n -0.0011158367,\n -0.011371493,\n + \ -0.010533075,\n 0.0008357766,\n -0.0041040243,\n -0.020361597,\n + \ 0.011568769,\n 0.033621293,\n 0.00024108941,\n 0.0061155246,\n + \ -0.009680565,\n -0.0007010308,\n -0.0072709923,\n -0.0031000355,\n + \ -0.0031264562,\n -0.0005310572,\n -0.0034487895,\n -0.012977876,\n + \ -0.014739259,\n 0.0037975435,\n 0.00037693614,\n 0.0038327712,\n + \ -0.01131513,\n 0.05210878,\n 0.023602543,\n -0.011082627,\n + \ -0.01335129,\n 0.010187844,\n -0.023461632,\n -0.005971091,\n + \ -0.00823623,\n -0.0066333716,\n 0.001223281,\n 0.025955752,\n + \ -0.0347204,\n -0.03119763,\n 0.04015955,\n 0.013590838,\n + \ -0.004181525,\n -0.020840693,\n 0.024053456,\n 0.0054743807,\n + \ -0.016444279,\n 0.009455108,\n -0.004861419,\n 0.01645837,\n + \ 0.011336266,\n 0.0056716558,\n 0.023813909,\n -0.010406256,\n + \ 0.028421689,\n 0.00940579,\n -0.0014126298,\n -0.009652384,\n + \ -0.018783396,\n -0.025702111,\n -0.011371493,\n -0.0016363255,\n + \ -0.017007923,\n 0.020220686,\n 0.020897057,\n 0.02449028,\n + \ -0.0036178823,\n -0.009927159,\n 0.037848614,\n -0.003952545,\n + \ 0.0023567316,\n -0.022714805,\n 0.021531155,\n 0.005900636,\n + \ -0.0009810908,\n -0.020643419,\n -0.0024588918,\n 0.023137538,\n + \ 0.00967352,\n -0.012759464,\n -0.011801272,\n 0.0016081434,\n + \ -0.0062176846,\n -0.013337198,\n -0.0137740215,\n -0.011230583,\n + \ -0.008398278,\n 0.020558871,\n 0.024419826,\n -0.0043541407,\n + \ 0.0060697286,\n -0.035114948,\n 0.015641088,\n -0.0068482603,\n + \ 0.021643884,\n -0.0095396545,\n -0.011667406,\n 0.00033686464,\n + \ 0.003272651,\n 0.0066439398,\n -0.0009414596,\n -0.014006524,\n + \ 0.013041286,\n 0.015232447,\n 0.00062352984,\n 0.008983057,\n + \ -0.024842557,\n 0.015161992,\n -0.000989017,\n -0.005136195,\n + \ -0.008461688,\n -0.018346574,\n -0.0037799296,\n 0.003015489,\n + \ 0.03370584,\n -0.0015112673,\n -0.017388381,\n 0.010878306,\n + \ 0.019375222,\n 0.0051855138,\n -0.027942592,\n 0.0037447019,\n + \ 0.041822296,\n 0.008877374,\n -0.007876908,\n 0.0048015323,\n + \ -0.0037411791,\n 0.009793294,\n 0.026364394,\n -0.03136672,\n + \ 0.019783862,\n 0.0051467633,\n 0.02647712,\n -0.007440085,\n + \ 0.012329686,\n -0.0190934,\n -0.03331129,\n -0.0064678015,\n + \ 0.010032842,\n 0.028999424,\n 0.024673464,\n -0.0008023103,\n + \ -0.0044809603,\n -0.0074541764,\n -0.004199139,\n 0.006245867,\n + \ 0.016204732,\n 0.020051593,\n 0.03319856,\n -0.0072991746,\n + \ 0.0053968797,\n -0.61549795,\n -0.050389666,\n -0.017684294,\n + \ -0.047289632,\n 0.03711588,\n -0.015288811,\n 0.015500178,\n + \ 0.012442416,\n -0.011399676,\n 0.0373977,\n 0.0060943877,\n + \ -0.0040864106,\n -0.017487017,\n -0.010061025,\n 0.00092560716,\n + \ -0.025476655,\n -0.0023021286,\n -0.003515722,\n -0.00907465,\n + \ -0.018417029,\n -0.0048297145,\n 0.02658985,\n -0.009060558,\n + \ -0.003193389,\n 0.015739726,\n -0.0052524465,\n 0.029675795,\n + \ 0.001246179,\n -0.009518518,\n 0.0093212435,\n -0.0035069152,\n + \ -0.005192559,\n 0.015556541,\n -0.011554678,\n 0.048783287,\n + \ -0.020023411,\n -0.02330663,\n 0.0086801,\n -0.002147127,\n + \ 0.021023877,\n 0.0015685123,\n -0.014795624,\n 0.026688488,\n + \ 0.016740192,\n -0.017388381,\n 0.008588508,\n 0.022968445,\n + \ -0.025180742,\n -0.006210639,\n 0.0004383644,\n 0.029055787,\n + \ 0.0049213064,\n -0.0043153903,\n 0.011695588,\n 0.0039137946,\n + \ 0.0011898148,\n 0.044020504,\n 0.002009739,\n 0.0030824216,\n + \ -0.022306165,\n -0.01604973,\n 0.016218822,\n -0.0062670037,\n + \ 0.0070455354,\n -0.02816805,\n 0.014105162,\n -0.0042555034,\n + \ 0.0002763171,\n 0.009243743,\n -0.032691285,\n 0.016655644,\n + \ 0.0040018638,\n 0.016951557,\n -0.015260629,\n 0.014288345,\n + \ 0.0050199437,\n -0.0034346983,\n -0.0046923263,\n 0.0028745783,\n + \ -0.0018230323,\n 0.00861669,\n -0.0013774021,\n -0.030605804,\n + \ -0.021517064,\n 0.034438577,\n 0.01054012,\n -0.03249401,\n + \ 0.017064286,\n 0.020206595,\n -0.004241412,\n 0.02174252,\n + \ 0.031141266,\n 0.013252651,\n -0.026181208,\n 0.00040357705,\n + \ 0.021362063,\n -0.03080308,\n 0.009102832,\n 0.017332017,\n + \ -0.017599747,\n -0.0076303147,\n -0.01218173,\n 0.014922444,\n + \ 0.001409107,\n 0.002312697,\n 0.009955341,\n -0.013745839,\n + \ 0.015852455,\n 0.02539211,\n -0.0005147644,\n -0.009476244,\n + \ -0.030183073,\n 0.003084183,\n 0.011864681,\n 0.006760191,\n + \ -0.026138935,\n 0.020629328,\n 0.024983468,\n 0.0010198412,\n + \ -0.009680565,\n 0.015993364,\n 0.004702895,\n 0.027815772,\n + \ 0.008870329,\n 0.026801215,\n 0.0025064491,\n 0.0067214407,\n + \ -0.011258765,\n -0.011575814,\n -0.025504837,\n -0.014894261,\n + \ 0.0005477904,\n -0.0015526598,\n -0.006672122,\n 0.034579486,\n + \ -0.008250321,\n 0.01098399,\n -0.008053047,\n 0.017599747,\n + \ -0.0033765726,\n -0.020727964,\n 0.009645337,\n 0.015852455,\n + \ -0.0064678015,\n -0.0062071164,\n -0.03209946,\n -0.022418894,\n + \ -0.006411437,\n 0.016204732,\n 0.019713407,\n -0.017134741,\n + \ -0.0017886852,\n -0.017980205,\n 0.0054743807,\n 0.019318858,\n + \ -0.008370096,\n 0.013626065,\n -0.040103186,\n -0.033903114,\n + \ -0.019840227,\n -0.0011818885,\n 0.016500643,\n -0.009659429,\n + \ 0.010962853,\n 0.0082855495,\n -0.015570633,\n -0.012569235,\n + \ 0.004635962,\n -0.029844888,\n -0.013936069,\n -0.017303834,\n + \ -0.040610466,\n 0.005439153,\n -0.02870351,\n -0.014795624,\n + \ 0.019304767,\n -0.0124565065,\n -0.03435403,\n 0.020234777,\n + \ -0.020868875,\n -0.00901124,\n 0.039934095,\n -0.03054944,\n + \ -0.009131013,\n 0.024025274,\n 0.008377141,\n -0.001932238,\n + \ 0.043175038,\n 0.017853387,\n 0.032324914,\n -0.032071277,\n + \ 0.027604407,\n -0.006474847,\n 0.011174219,\n 0.0001123983,\n + \ 0.00016336834,\n 0.012653781,\n 0.008405323,\n 0.010688077,\n + \ 0.00907465,\n 0.014126298,\n 0.0055554044,\n 0.022348437,\n + \ -0.012710146,\n 0.0024606532,\n -0.0035403813,\n 0.010462619,\n + \ -0.025547111,\n 0.010927625,\n 0.04015955,\n 0.01039921,\n + \ -0.0016891671,\n 0.0048015323,\n -0.0040828874,\n -0.008074183,\n + \ 0.023250267,\n -0.008024865,\n 0.01251287,\n 0.010469665,\n + \ -0.0334522,\n 0.0064959833,\n -0.00071071833,\n 0.016951557,\n + \ 0.006989171,\n 0.008356005,\n -0.013943114,\n 0.031225812,\n + \ 0.018121116,\n 0.017177016,\n -0.019403404,\n 0.0029908298,\n + \ 0.00450562,\n 0.03170491,\n 0.0059358636,\n 0.028816238,\n + \ -0.003730611,\n 0.0037447019,\n 0.0029062834,\n 0.021094332,\n + \ 0.0006649224,\n 0.007094854,\n 0.008919648,\n 0.024969377,\n + \ -0.017416563,\n 0.010117388,\n 0.009314197,\n 0.026096663,\n + \ -0.008060092,\n -0.04303413,\n 0.018107025,\n -0.026434848,\n + \ -0.010638759,\n -0.021657975,\n 0.009462154,\n 0.008750555,\n + \ -0.0069786026,\n -0.02330663,\n 0.015641088,\n 0.013316061,\n + \ 0.04278049,\n 0.036354963,\n 0.008778737,\n 0.0061049564,\n + \ 0.0010850125,\n 0.03198673,\n -0.009441017,\n -0.018543849,\n + \ -0.011963319,\n -0.0010427393,\n -0.01857203,\n -0.0039490224,\n + \ -0.012259231,\n -0.008658962,\n -0.022334347,\n 0.032634918,\n + \ 0.0074048573,\n -0.034551304,\n 0.028886694,\n -0.003299072,\n + \ 0.008130548,\n -0.016740192,\n -0.026322119,\n 0.02790032,\n + \ 0.014795624,\n 0.004259026,\n -0.023193901,\n -0.03136672,\n + \ -0.024856647,\n -0.023757545,\n 0.023447542,\n 0.0137106115,\n + \ -0.011075581,\n -0.026082572,\n 0.01125172,\n 0.016909285,\n + \ 0.046444166,\n 0.007820544,\n -0.013139923,\n 0.0011537063,\n + \ 0.028914876,\n -0.011914,\n 0.018867943,\n -0.010533075,\n + \ -0.002552245,\n 0.01604973,\n 0.02079842,\n -0.019671135,\n + \ -0.03147945,\n 0.001011915,\n -0.039765,\n 0.0026720192,\n + \ -0.015035172,\n 0.0047839186,\n -0.024631191,\n -0.0125974165,\n + \ 0.0074119032,\n -0.018769305,\n -0.016021548,\n 0.0021682635,\n + \ -0.0011184787,\n -0.0039314087,\n -0.007397812,\n -0.024969377,\n + \ 0.029196698,\n 0.06442437,\n 0.017317925,\n 0.00095467,\n + \ 0.007006785,\n -0.027872138,\n -0.000106673804,\n -0.01975568,\n + \ -0.0036354961,\n 0.010758532,\n -0.016373824,\n -0.02384209,\n + \ 0.015359267,\n 0.018459301,\n 0.008257368,\n 0.0034206074,\n + \ -0.0036425416,\n -0.017303834,\n -0.026293937,\n 0.051009674,\n + \ -0.013914932,\n -0.018910216,\n -0.0017922081,\n -0.013125832,\n + \ 0.012097184,\n 0.00276185,\n 0.018078843,\n 0.02013614,\n + \ 0.027407132,\n 0.005058694,\n -0.029140333,\n -0.02093933,\n + \ -0.012139457,\n 0.0077571343,\n 0.0021735476,\n -0.005710406,\n + \ 0.043654136,\n 0.009906023,\n 0.011005126,\n 0.025913479,\n + \ -0.0019269539,\n 0.006488938,\n 0.00770077,\n 0.010244208,\n + \ -0.016247004,\n 0.016148366,\n -0.008532143,\n -0.0025152562,\n + \ 0.029422155,\n -0.006622803,\n -0.0030718534,\n 0.008193958,\n + \ 0.006672122,\n -0.020629328,\n -0.0011704395,\n 0.0060098413,\n + \ 0.030183073,\n -0.017529292,\n -0.0076937242,\n -0.029929433,\n + \ -0.0058759763,\n -0.014767442,\n -0.0036425416,\n -0.0010277674,\n + \ -0.01778293,\n -0.033874933,\n -0.023983002,\n -0.017627928,\n + \ -0.028943058,\n -0.020840693,\n -0.009335334,\n -0.019445676,\n + \ 0.0020801942,\n -0.069215335,\n 0.03736952,\n 0.014041752,\n + \ -0.008116457,\n 0.017177016,\n -0.020742055,\n -0.013456972,\n + \ -0.007263947,\n 0.017980205,\n -0.0025504837,\n 0.022545712,\n + \ -0.052165143,\n -0.03435403,\n -0.005513131,\n 0.013104696,\n + \ 0.032634918,\n -0.016077911,\n 0.005351084,\n 0.0050446033,\n + \ -0.008243276,\n 0.028914876,\n 0.0052876743,\n 0.011921045,\n + \ 0.013788112,\n 0.018501576,\n 0.010251254,\n 0.007623269,\n + \ -0.014936535,\n -0.0004042376,\n -0.023813909,\n 0.008257368,\n + \ -0.01764202,\n 0.014851988,\n 0.014739259,\n 0.006897579,\n + \ 0.0015420915,\n -0.015993364,\n 0.006865874,\n 0.03201491,\n + \ -0.010568303,\n -0.017219288,\n -0.025490746,\n -0.01355561,\n + \ -0.008933739,\n 0.017825205,\n 0.010758532,\n -0.024870738,\n + \ -0.009433972,\n 0.005203128,\n -0.00078733853,\n 0.0002857845,\n + \ -0.002464176,\n -0.004547893,\n 0.009229651,\n 0.0069151926,\n + \ -0.013203333,\n -0.025208924,\n 0.0025064491,\n 0.008334869,\n + \ 0.029534884,\n -0.008785782,\n -0.013759931,\n -0.024673464,\n + \ -0.014422211,\n -0.0181493,\n -0.0060556373,\n -0.007855772,\n + \ -0.013372426,\n -0.024645282,\n 0.0060556373,\n 0.021587519,\n + \ -0.044443235,\n 0.007714861,\n -0.026646214,\n -0.0206716,\n + \ -0.009081695,\n 0.020262958,\n 0.0061577978,\n -0.015063354,\n + \ 0.004702895,\n -0.023588452,\n -0.018938398,\n -0.015626997,\n + \ -0.029478518,\n -0.022432985,\n -0.0041885707,\n 0.0036848148,\n + \ 0.02594166,\n 0.020925239,\n -0.0046993718,\n 0.044584148,\n + \ -0.00585484,\n -0.018205663,\n -0.0042660716,\n -0.020770237,\n + \ -0.025335744,\n 0.0067672366,\n -0.0130835585,\n -0.015260629,\n + \ -0.026237573,\n 0.015781999,\n 0.02106615,\n -0.028125776,\n + \ 0.018008389,\n 0.0076796333,\n -0.012386051,\n -0.022320256,\n + \ -0.03872226,\n 0.0019657044,\n 0.0017111844,\n 0.0037376564,\n + \ 0.03643951,\n 0.00190934,\n 0.0077219065,\n 0.018121116,\n + \ 0.0005398641,\n 0.02802714,\n -0.006196548,\n 0.027829863,\n + \ -0.02172843,\n 0.034438577,\n 0.010173753,\n -0.009969432,\n + \ -0.019812046,\n -0.041850477,\n -0.0142813,\n 0.0057526794,\n + \ 0.025462564,\n 0.03331129,\n -0.011836499,\n -0.00053413963,\n + \ 0.021009786,\n -0.015908819,\n 0.0381868,\n -0.012569235,\n + \ -0.008158729,\n -0.013090604,\n -0.006277572,\n -0.011794226,\n + \ -0.021362063,\n -0.010201935,\n -0.0055096084,\n -0.001640729,\n + \ 0.022122981,\n 0.0054990402,\n 0.01540154,\n -0.030154891,\n + \ -0.028943058,\n -0.0073414478,\n -0.0070596263,\n 0.03762316,\n + \ 0.01882567,\n 0.00040665947,\n 0.0109980805,\n -0.0018811579,\n + \ -0.006407914,\n -0.009652384,\n 0.0015737964,\n 0.009138059,\n + \ -0.004195616,\n 0.021037968,\n -0.0057702935,\n 0.005379266,\n + \ 0.013309016,\n -0.0009687611,\n -0.017261561,\n -0.032860376,\n + \ 0.01592291,\n -0.011448994,\n -0.0002809407,\n -0.033649474,\n + \ -0.017599747,\n -0.026237573,\n 0.032888558,\n 0.021418426,\n + \ -0.0017173492,\n 0.006710872,\n -0.0048121004,\n -0.028999424,\n + \ 0.02502574,\n -0.0024606532,\n 0.022841625,\n -0.0022845147,\n + \ 0.00020388018,\n 0.00050859957,\n -0.0018582599,\n -0.03252219,\n + \ -0.006178934,\n -0.020375688,\n 0.010413301,\n -0.006971557,\n + \ 0.017543383,\n 0.019642953,\n 0.011195355,\n 0.013464018,\n + \ -0.02053069,\n -0.015824271,\n 0.03359311,\n -0.0016222345,\n + \ -0.008750555,\n 0.020262958,\n 0.004075842,\n 0.019952955,\n + \ -0.010166707,\n -0.00094057893,\n -0.011195355,\n 0.00060899847,\n + \ 0.005259492,\n 0.016134275,\n -0.012357868,\n -0.009504427,\n + \ -0.0029890684,\n -0.018783396,\n -0.006457233,\n -0.031930365,\n + \ -0.003249753,\n 0.012963785,\n -0.03291674,\n -0.02605439,\n + \ -0.0033008333,\n 0.0025645748,\n 0.007383721,\n 0.02671667,\n + \ -0.017444745,\n -0.009779203,\n 0.023687089,\n -0.031028537,\n + \ 0.018910216,\n 0.00067593105,\n -0.0029855454,\n -0.04596507,\n + \ -0.002060819,\n 0.0042484575,\n -0.029027605,\n 0.022221617,\n + \ -0.009596019,\n -0.031113083,\n -0.011286947,\n 0.014429256,\n + \ 0.021178879,\n 0.002501165,\n 0.0014504995,\n 0.018952489,\n + \ 0.0046324395,\n 0.012604462,\n -0.018050661,\n -0.01868476,\n + \ 0.045345064,\n -0.021094332,\n 0.0082080485,\n 0.038243163,\n + \ -0.0012999013,\n -0.009032376,\n -0.012484688,\n 0.008186912,\n + \ 0.015725635,\n -0.004716986,\n -0.014365846,\n -0.0012268039,\n + \ 0.011843544,\n 0.006534734,\n -0.017825205,\n 0.0070243985,\n + \ -0.02329254,\n -0.0074894037,\n -0.004424596,\n 0.013020149,\n + \ 0.014626531,\n -0.0011581099,\n 0.012195822,\n -0.021221152,\n + \ 0.004716986,\n 0.009335334,\n -0.014076979,\n -0.04435869,\n + \ 0.007672588,\n -0.019600678,\n -0.005890067,\n 0.01697974,\n + \ 0.023024809,\n 0.0034065163,\n -0.014513803,\n -0.030493077,\n + \ -0.027956683,\n 0.006048592,\n -0.0018741124,\n -0.012435369,\n + \ 0.009145104,\n 0.033649474,\n -0.006654508,\n 0.007820544,\n + \ 0.011892864,\n -0.0039349315,\n 0.018797487,\n -0.017994298,\n + \ 0.006425528,\n 0.0024025275,\n -0.02911215,\n -0.021037968,\n + \ -0.029844888,\n -0.024053456,\n -0.015232447,\n 0.020206595,\n + \ 0.007186446,\n 0.0028111686,\n 0.024828466,\n 0.010385118,\n + \ -0.022447076,\n -0.0030190118,\n -0.031253994,\n 0.015894728,\n + \ -0.021827068,\n 0.014936535,\n -0.040215913,\n -0.028365325,\n + \ 0.018262027,\n -0.011956274,\n 0.00024571305,\n 0.0070103076,\n + \ 0.019121582,\n 0.0057738163,\n 0.029422155,\n -0.020446142,\n + \ 0.015739726,\n 0.0045267562,\n -0.009645337,\n 0.004396414,\n + \ -0.01335129,\n -0.015415631,\n 0.017923841,\n -0.01006807,\n + \ -0.013435836,\n -0.025223017,\n 0.009765112,\n -0.0018318391,\n + \ -0.0062810946,\n 0.016923375,\n -0.017867478,\n -0.014429256,\n + \ 0.004033569,\n -0.0055096084,\n 0.0029767386,\n -0.028421689,\n + \ -0.009849658,\n -0.01251287,\n -0.035622224,\n -0.0029591247,\n + \ -0.006485415,\n -0.01790975,\n 0.0059922277,\n -0.031225812,\n + \ -0.0052630147,\n -0.0055272225,\n -0.024138004,\n -0.0031916273,\n + \ -0.018064752,\n -0.01330197,\n 0.007362584,\n -0.024631191,\n + \ -0.0222498,\n -0.00730622,\n 0.027872138,\n -0.0025628135,\n + \ 0.021517064,\n 0.21057695,\n 0.0073273564,\n -0.011611042,\n + \ 0.047035992,\n -0.017543383,\n 0.0030084436,\n -0.009906023,\n + \ -0.006422005,\n -0.0066897357,\n 0.03410039,\n 0.012787647,\n + \ -0.011138991,\n -0.01999523,\n -0.003267367,\n -0.009983524,\n + \ -0.016261095,\n -0.025955752,\n -0.01699383,\n -0.03142309,\n + \ -0.0220948,\n 0.010011706,\n -0.017078377,\n -0.0040124324,\n + \ -0.003221571,\n -0.0023884363,\n 0.03801771,\n 0.0070878086,\n + \ 0.006376209,\n 0.041625023,\n 0.014992899,\n -0.021601612,\n + \ 0.007869863,\n 0.02804123,\n 0.0054532443,\n 0.018670669,\n + \ -0.019177947,\n 0.018529758,\n 0.0026103707,\n 0.0582243,\n + \ -0.0010066308,\n 0.036552235,\n -0.022714805,\n 0.0028587258,\n + \ -0.0012576281,\n 0.006566439,\n 0.013626065,\n -0.0021171833,\n + \ -0.009708747,\n 0.0039631138,\n 0.019952955,\n -0.008588508,\n + \ 0.0181493,\n 0.033001285,\n 0.015626997,\n 0.0057385885,\n + \ 0.010490802,\n 0.023785727,\n 0.016740192,\n 0.0024659373,\n + \ 0.012202867,\n 0.007982591,\n 0.045739613,\n -0.0068024644,\n + \ 0.0038327712,\n -0.033001285,\n 0.017050195,\n -0.03145127,\n + \ -0.0105119385,\n 0.004382323,\n -0.011780134,\n -0.0043224357,\n + \ -0.0053898343,\n 0.0051890365,\n -0.020897057,\n -0.0013941353,\n + \ -0.027801681,\n -0.009166242,\n 0.0033836183,\n 0.017656112,\n + \ 0.027632589,\n 0.005978137,\n 0.009250788,\n 0.006365641,\n + \ 0.0024606532,\n -0.0007472671,\n -0.011040353,\n 0.032578554,\n + \ 0.02437755,\n -0.009793294,\n 0.005710406,\n -0.0141967535,\n + \ -0.031028537,\n -0.0031141266,\n 0.007383721,\n 0.015880637,\n + \ -0.0061049564,\n 0.015415631,\n 0.031000355,\n -0.0038785671,\n + \ -0.016782464,\n -0.022855716,\n -0.0036178823,\n 0.01647246,\n + \ -0.040610466,\n 0.004304822,\n 0.024208458,\n 0.0031405473,\n + \ 0.012287414,\n 0.019276584,\n -0.022940263,\n 0.0034082776,\n + \ -0.018050661,\n 0.018853853,\n 0.0057808617,\n -0.005710406,\n + \ 0.013872659,\n 0.0042343666,\n 0.003906749,\n 0.0016979739,\n + \ -0.0069046244,\n -0.005925295,\n -0.0334522,\n -0.020305233,\n + \ -0.0026684965,\n -0.018205663,\n 0.0052066506,\n 0.0022968445,\n + \ 0.009441017,\n 0.008130548,\n -0.01633155,\n 0.034410395,\n + \ -0.0068165553,\n 0.018839762,\n -0.017416563,\n 0.0035315745,\n + \ 0.0072780377,\n 0.010758532,\n -0.004294254,\n -0.01368243,\n + \ -0.005248924,\n 0.012498779,\n -0.009102832,\n -0.0035333359,\n + \ -0.007383721,\n 0.0032902649,\n -0.03162036,\n 0.016824737,\n + \ -0.020572962,\n 0.020305233,\n -0.033536747,\n -0.020558871,\n + \ -0.019586587,\n -0.00730622,\n -0.012294459,\n 0.017036105,\n + \ -0.012188775,\n -0.0044316417,\n -0.03331129,\n -0.013576746,\n + \ 0.00015632281,\n -0.04396414,\n 0.02857669,\n 0.009391698,\n + \ 0.008644871,\n -0.008856238,\n 0.014182663,\n -0.18183117,\n + \ 0.004826192,\n 0.010955807,\n -0.009145104,\n 0.01881158,\n + \ 0.011568769,\n 0.021376153,\n -0.0016874056,\n -0.017261561,\n + \ 0.0072780377,\n 0.0046324395,\n 0.003864476,\n -0.024419826,\n + \ -0.0052982424,\n 0.0054743807,\n -0.013203333,\n -0.010962853,\n + \ -0.0061296155,\n 0.03999046,\n 0.017684294,\n 0.00612257,\n + \ -0.0065699616,\n 0.0347204,\n -0.01218173,\n 0.002312697,\n + \ 0.033790387,\n -0.020812511,\n 0.015119718,\n -0.022728896,\n + \ -0.0115476325,\n -0.033621293,\n -0.02897124,\n 0.017726567,\n + \ 0.0013659531,\n 0.017952023,\n -0.009497382,\n -0.002046728,\n + \ -0.0030084436,\n 0.009588974,\n 0.031000355,\n 0.009229651,\n + \ 0.024786193,\n 0.031535815,\n -0.0043576634,\n -0.020037502,\n + \ 0.008257368,\n 0.013654247,\n -0.000013437432,\n 0.0054743807,\n + \ -0.014239026,\n 0.009786248,\n -0.02791441,\n -0.0075457683,\n + \ 0.016359733,\n -0.013703566,\n 0.021686157,\n -0.015035172,\n + \ 0.021023877,\n 0.000308022,\n -0.012428324,\n 0.0003086825,\n + \ -0.04001864,\n 0.0070138304,\n -0.016810646,\n -0.014640622,\n + \ -0.0025434382,\n -0.016965648,\n 0.007848727,\n -0.01027239,\n + \ 0.02723804,\n -0.012710146,\n -0.022545712,\n 0.023828,\n + \ 0.0077994075,\n 0.025194833,\n 0.019192038,\n -0.03291674,\n + \ 0.015598815,\n -0.00894783,\n -0.005868931,\n -0.0021929229,\n + \ 0.034044027,\n -0.0050410805,\n 0.033762205,\n -0.00861669,\n + \ 0.01750111,\n -0.019713407,\n -0.00074902846,\n -0.0027283835,\n + \ -0.011103763,\n 0.015951091,\n -0.035622224,\n 0.010096252,\n + \ 0.0064818924,\n 0.0017631452,\n 0.01645837,\n 0.0151056275,\n + \ -0.005942909,\n 0.031648543,\n -0.0132244695,\n -0.035058584,\n + \ 0.0017525769,\n 0.0012215197,\n 0.010124434,\n 0.011751953,\n + \ 0.01974159,\n 0.019051127,\n -0.012653781,\n 0.016317459,\n + \ -0.0016072628,\n -0.018853853,\n 0.0004619229,\n 0.019459767,\n + \ 0.015091537,\n -0.012364915,\n 0.045373246,\n 0.024969377,\n + \ 0.0014152719,\n 0.00083973975,\n -0.016824737,\n 0.047345996,\n + \ -0.027632589,\n -0.018867943,\n 0.024250733,\n -0.003138786,\n + \ -0.013069468,\n -0.09486108,\n -0.017627928,\n 0.027463496,\n + \ -0.0036672011,\n -0.011160128,\n 0.013809249,\n -0.0055976775,\n + \ 0.030098526,\n -0.012928557,\n 0.01566927,\n -0.031028537,\n + \ -0.021672066,\n 0.0016319221,\n 0.02108024,\n -0.006728486,\n + \ -0.03765134,\n 0.005368698,\n -0.024673464,\n -0.016740192,\n + \ 0.030267619,\n -0.0074119032,\n -0.010096252,\n 0.01290742,\n + \ 0.00056496385,\n 0.015739726,\n -0.018233845,\n -0.034692217,\n + \ 0.01323856,\n 0.007834635,\n 0.014837897,\n 0.031225812,\n + \ -0.015457904,\n -0.013893795,\n -0.021953888,\n 0.0012250424,\n + \ 0.00025033668,\n -0.03567859,\n -0.00026024444,\n 0.033226743,\n + \ -0.03294492,\n 0.0020555349,\n 0.022207526,\n 0.03844044,\n + \ -0.019445676,\n 0.01448562,\n -0.0003216727,\n -0.037482247,\n + \ 0.025758477,\n -0.00069354486,\n -0.0045338017,\n -0.023503905,\n + \ -0.009828522,\n -0.0230389,\n -0.0033941865,\n 0.0060168873,\n + \ -0.019417495,\n 0.024701646,\n 0.018107025,\n -0.0071582636,\n + \ -0.034664035,\n 0.01020898,\n 0.006594621,\n -0.0021259903,\n + \ 0.019854318,\n -0.0039243633,\n 0.00907465,\n -0.01579609,\n + \ 0.01592291,\n 0.0039631138,\n 0.0026861103,\n -0.027998956,\n + \ 0.017092468,\n -0.030577622,\n 0.0052876743,\n -0.012160594,\n + \ -0.020911148,\n -0.01330197,\n -0.015767908,\n -0.020065684,\n + \ -0.011892864,\n -0.009004194,\n -0.027970774,\n -0.011660361,\n + \ -0.023672998,\n 0.021897523,\n 0.0334522,\n -0.020897057,\n + \ 0.017078377,\n 0.009758066,\n -0.0074189487,\n -0.009194423,\n + \ -0.0041462975,\n -0.029901251,\n -0.009624201,\n -0.008292595,\n + \ -0.0003886053,\n -0.020854784,\n 0.008687145,\n -0.00013507612,\n + \ 0.013893795,\n -0.0009819715,\n -0.02396891,\n -0.070737176,\n + \ 0.020826602,\n 0.008010774,\n -0.0039349315,\n -0.0081446385,\n + \ -0.018247936,\n 0.008257368,\n -0.013435836,\n 0.021700248,\n + \ 0.011146037,\n -0.010117388,\n 0.021517064,\n -0.018008389,\n + \ -0.00809532,\n 0.0038785671,\n -0.026308028,\n -0.00009676602,\n + \ 0.009448063,\n 0.028590782,\n -0.014711077,\n 0.0020678646,\n + \ 0.0012312073,\n 0.008574416,\n 0.037284974,\n 0.0048860786,\n + \ 0.010237163,\n -0.014422211,\n 0.051094223,\n -0.005368698,\n + \ -0.03184582,\n 0.010631712,\n -0.03421312,\n -0.0066615534,\n + \ 0.011899909,\n -0.0139924325,\n -0.010053978,\n 0.010681031,\n + \ 0.0015570633,\n 0.0061613205,\n 0.010420347,\n -0.016092002,\n + \ -0.0102301175,\n 0.029365791,\n -0.026420757,\n -0.024166185,\n + \ -0.0074541764,\n -0.0064466647,\n 0.017726567,\n 0.023391176,\n + \ -0.0013800442,\n 0.014239026,\n 0.011864681,\n -0.044696875,\n + \ -0.02305299,\n -0.0059957504,\n -0.009638292,\n -0.00086219737,\n + \ 0.010082161,\n 0.025575293,\n -0.028182141,\n 0.048416916,\n + \ 0.019558406,\n -0.016035639,\n -0.014894261,\n 0.024152094,\n + \ -0.010159662,\n -0.030352166,\n -0.008905556,\n -0.002289799,\n + \ -0.04596507,\n -0.013541519,\n 0.007827589,\n 0.008933739,\n + \ 0.01137854,\n 0.013076513,\n -0.012766509,\n 0.009067603,\n + \ -0.009236696,\n -0.014351755,\n 0.038412258,\n -0.006668599,\n + \ -0.013471063,\n -0.010201935,\n -0.010061025,\n 0.023081174,\n + \ 0.026646214,\n -0.006474847,\n -0.01230855,\n 0.0041427747,\n + \ 0.024898922,\n -0.027280312,\n -0.01579609,\n -0.043879595,\n + \ 0.010561258,\n 0.0004374837,\n -0.0049213064,\n 0.002032637,\n + \ 0.011716725,\n 0.016218822,\n 0.0206716,\n 0.02802714,\n + \ 0.0115476325,\n -0.014119253,\n -0.01554245,\n -0.009039422,\n + \ -0.024067549,\n -0.0093212435,\n -0.031535815,\n 0.022559803,\n + \ 0.0373977,\n 0.005699838,\n -0.006245867,\n 0.0027266222,\n + \ 0.027590316,\n 0.008539189,\n 0.010096252,\n -0.010892398,\n + \ -0.026857581,\n -0.022827534,\n 0.014894261,\n 0.0028534418,\n + \ -0.0063621183,\n 0.013611974,\n 0.0022986059,\n 0.03686224,\n + \ 0.006274049,\n 0.00001782025,\n -0.0048860786,\n 0.0016160696,\n + \ 0.0064783697,\n 0.024053456,\n -0.01540154,\n -0.011068536,\n + \ -0.02844987,\n -0.0109980805,\n 0.0049776705,\n -0.017923841,\n + \ 0.03751043,\n -0.028238505,\n 0.12546688,\n -0.0037059516,\n + \ -0.020319324,\n 0.021249333,\n 0.0033748113,\n 0.006640417,\n + \ 0.011730816,\n 0.0045690294,\n -0.023109356,\n -0.015767908,\n + \ 0.025039831,\n -0.016120184,\n -0.010131479,\n -0.001992125,\n + \ 0.0045690294,\n 0.002712531,\n -0.004287208,\n 0.014922444,\n + \ -0.012336732,\n 0.006675645,\n 0.010681031,\n 0.018614303,\n + \ -0.0043999366,\n -0.0013562655,\n 0.004960057,\n 0.002932704,\n + \ 0.038130436,\n 0.015753817,\n -0.00049803127,\n -0.02436346,\n + \ 0.009476244,\n -0.013907886,\n -0.014936535,\n -0.0073132655,\n + \ -0.0045408476,\n 0.010828988,\n -0.017458836,\n -0.03491767,\n + \ 0.035312224,\n -0.012851056,\n -0.022728896,\n 0.0033025946,\n + \ -0.03170491,\n -0.018867943,\n 0.020333415,\n 0.0005310572,\n + \ 0.007031444,\n 0.013661292,\n -0.04475324\n ]\n + \ }\n ],\n \"model\": \"ada\",\n \"usage\": {\n \"prompt_tokens\": + 8,\n \"total_tokens\": 8\n }\n}\n" + headers: + Content-Length: + - '33446' + Content-Type: + - application/json + Date: + - Mon, 26 Feb 2024 21:11:59 GMT + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + access-control-allow-origin: + - '*' + apim-request-id: + - efa7a0dd-4812-477d-adb7-dd4c01153792 + azureml-model-session: + - wc25717d3dfd7-2 + x-content-type-options: + - nosniff + x-ms-client-request-id: + - efa7a0dd-4812-477d-adb7-dd4c01153792 + x-ms-region: + - Japan East + x-ratelimit-remaining-requests: + - '329' + x-ratelimit-remaining-tokens: + - '329982' + x-request-id: + - c16423ca-c3cc-445b-830e-5c6a18fa1109 + status: + code: 200 + message: OK +version: 1 diff --git a/packages/opentelemetry-instrumentation-openai/tests/test_chat.py b/packages/opentelemetry-instrumentation-openai/tests/test_chat.py index 1ea16a069..796d64206 100644 --- a/packages/opentelemetry-instrumentation-openai/tests/test_chat.py +++ b/packages/opentelemetry-instrumentation-openai/tests/test_chat.py @@ -22,3 +22,4 @@ def test_chat_streaming(exporter, openai_client, vcr): == "Tell me a joke about opentelemetry" ) assert open_ai_span.attributes.get("llm.completions.0.content") + assert open_ai_span.attributes.get("openai.api_base") == "https://api.openai.com/v1/" diff --git a/packages/opentelemetry-instrumentation-openai/tests/test_completions.py b/packages/opentelemetry-instrumentation-openai/tests/test_completions.py index 28a73831d..8f64e11e9 100644 --- a/packages/opentelemetry-instrumentation-openai/tests/test_completions.py +++ b/packages/opentelemetry-instrumentation-openai/tests/test_completions.py @@ -18,6 +18,7 @@ def test_completion(exporter, openai_client): == "Tell me a joke about opentelemetry" ) assert open_ai_span.attributes.get("llm.completions.0.content") + assert open_ai_span.attributes.get("openai.api_base") == "https://api.openai.com/v1/" @pytest.mark.vcr @@ -80,6 +81,7 @@ def test_completion_streaming(exporter, openai_client): == "Tell me a joke about opentelemetry" ) assert open_ai_span.attributes.get("llm.completions.0.content") + assert open_ai_span.attributes.get("openai.api_base") == "https://api.openai.com/v1/" @pytest.mark.vcr @@ -91,7 +93,7 @@ async def test_async_completion_streaming(exporter, async_openai_client): stream=True, ) - async for part in response: + async for _ in response: pass spans = exporter.get_finished_spans() @@ -104,3 +106,4 @@ async def test_async_completion_streaming(exporter, async_openai_client): == "Tell me a joke about opentelemetry" ) assert open_ai_span.attributes.get("llm.completions.0.content") + assert open_ai_span.attributes.get("openai.api_base") == "https://api.openai.com/v1/" diff --git a/packages/opentelemetry-instrumentation-openai/tests/test_embeddings.py b/packages/opentelemetry-instrumentation-openai/tests/test_embeddings.py index 2766fb2a9..c21e8f3b1 100644 --- a/packages/opentelemetry-instrumentation-openai/tests/test_embeddings.py +++ b/packages/opentelemetry-instrumentation-openai/tests/test_embeddings.py @@ -1,3 +1,4 @@ +import openai import pytest @@ -19,3 +20,34 @@ def test_embeddings(exporter, openai_client): ) assert open_ai_span.attributes["llm.request.model"] == "text-embedding-ada-002" assert open_ai_span.attributes["llm.usage.prompt_tokens"] == 8 + assert open_ai_span.attributes["openai.api_base"] == "https://api.openai.com/v1/" + + +@pytest.mark.vcr +def test_azure_openai_embeddings(exporter): + api_key = "redacted" + azure_deployment = "redacted" + + openai_client = openai.AzureOpenAI( + api_key=api_key, + azure_endpoint=f"https://{azure_deployment}.openai.azure.com", + api_version="2023-07-01-preview", + ) + openai_client.embeddings.create( + input="Tell me a joke about opentelemetry", + model="embedding", + ) + + spans = exporter.get_finished_spans() + assert [span.name for span in spans] == [ + "openai.embeddings", + ] + open_ai_span = spans[0] + assert ( + open_ai_span.attributes["llm.prompts.0.content"] + == "Tell me a joke about opentelemetry" + ) + assert open_ai_span.attributes["llm.request.model"] == "embedding" + assert open_ai_span.attributes["llm.usage.prompt_tokens"] == 8 + assert open_ai_span.attributes["openai.api_base"] == "https://redacted.openai.azure.com/openai/" + assert open_ai_span.attributes["openai.api_version"] == "2023-07-01-preview" diff --git a/packages/opentelemetry-instrumentation-openai/tests/test_functions.py b/packages/opentelemetry-instrumentation-openai/tests/test_functions.py index b28c803dc..cceb324ef 100644 --- a/packages/opentelemetry-instrumentation-openai/tests/test_functions.py +++ b/packages/opentelemetry-instrumentation-openai/tests/test_functions.py @@ -46,3 +46,4 @@ def test_open_ai_function_calls(exporter, openai_client): open_ai_span.attributes["llm.completions.0.function_call.name"] == "get_current_weather" ) + assert open_ai_span.attributes["openai.api_base"] == "https://api.openai.com/v1/" diff --git a/packages/opentelemetry-instrumentation-openai/tests/test_vision.py b/packages/opentelemetry-instrumentation-openai/tests/test_vision.py index b3e74615b..419214d97 100644 --- a/packages/opentelemetry-instrumentation-openai/tests/test_vision.py +++ b/packages/opentelemetry-instrumentation-openai/tests/test_vision.py @@ -39,3 +39,4 @@ def test_vision(exporter, openai_client): ] assert open_ai_span.attributes.get("llm.completions.0.content") + assert open_ai_span.attributes["openai.api_base"] == "https://api.openai.com/v1/"