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

[BUG] No easy way to change gRPC port on the client side #5955

Closed
HKozubek opened this issue Jan 8, 2025 · 5 comments · Fixed by #6017
Closed

[BUG] No easy way to change gRPC port on the client side #5955

HKozubek opened this issue Jan 8, 2025 · 5 comments · Fixed by #6017
Assignees
Labels
bug Something isn't working priority: medium

Comments

@HKozubek
Copy link

HKozubek commented Jan 8, 2025

Describe the bug
Correct me if I'm wrong but currently there doesn't exists an easy way to change gRPC port on the client side of the app. The Collector Endpoint is either treated as HTTP by default, or as gRPC, but the port is forced to be 4317.

To Reproduce
Steps to reproduce the behavior:

  1. This one defaults to HTTP, since when passing endpoint like this only the endpoint with port 4317 will be interpreted as gRPC
from phoenix.otel import register
from openinference.instrumentation.llama_index import LlamaIndexInstrumentor

tracer_provider = register(
  endpoint="http://localhost:8188",
)
LlamaIndexInstrumentor().instrument(tracer_provider=tracer_provider)

Check for gRPC port:

def _maybe_grpc_endpoint(parsed_endpoint: ParseResult) -> bool:
if not parsed_endpoint.path and parsed_endpoint.port == 4317:
return True
return False

2. This one will get the endpoint from env variable and will default to gRPC, but will change the port from 8188 to 4317

import os
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "http://localhost:8188"

from phoenix.otel import register
from openinference.instrumentation.llama_index import LlamaIndexInstrumentor

tracer_provider = register()
LlamaIndexInstrumentor().instrument(tracer_provider=tracer_provider)

The code overwrites the port from env variable with _DEFAULT_GRPC_PORT variable

def _construct_grpc_endpoint(parsed_endpoint: ParseResult) -> ParseResult:
return parsed_endpoint._replace(netloc=f"{parsed_endpoint.hostname}:{_DEFAULT_GRPC_PORT}")

Expected behavior
The port shouldn't be overwritten, or there should be an easy way to define a port as gRPC using env variables

Environment (please complete the following information):

  • OS: Ubuntu 22.04
  • Browser: chrome
  • Version: 7.5.2

Additional context
Currently the only way I found to change this behavior is to overwrite the "_maybe_grpc_endpoint" function

import os
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "http://localhost:8188"

import phoenix.otel.otel

def _new_maybe_grpc_endpoint(parsed_endpoint) -> bool:
    if not parsed_endpoint.path and parsed_endpoint.port == 8188:
        return True
    return False

phoenix.otel.otel._maybe_grpc_endpoint = _new_maybe_grpc_endpoint

from openinference.instrumentation.llama_index import LlamaIndexInstrumentor

tracer_provider = phoenix.otel.otel.register()
LlamaIndexInstrumentor().instrument(tracer_provider=tracer_provider)

This will set the Collector endpoint to http://localhost:8188 and the type to gRPC

@HKozubek HKozubek added bug Something isn't working triage issues that need triage labels Jan 8, 2025
@github-project-automation github-project-automation bot moved this to 📘 Todo in phoenix Jan 8, 2025
@cephalization
Copy link
Contributor

Hey @HKozubek thanks for reaching out! Let me take a look at this and get back to you soon

@cephalization cephalization self-assigned this Jan 8, 2025
@cephalization
Copy link
Contributor

I was able to replicate this issue, and it does not quite work how I would expect either.

This is in fact quite suspicious.

def _maybe_grpc_endpoint(parsed_endpoint: ParseResult) -> bool:
if not parsed_endpoint.path and parsed_endpoint.port == 4317:
return True
return False

Any thoughts @axiomofjoy @RogerHYang ?

Here is a minimal reproduction

docker compose up -d

# docker-compose.yml
services:
  phoenix:
    image: arizephoenix/phoenix:latest
    ports:
      - 6006:6006
      - 4999:4999
    environment:
      - PHOENIX_GRPC_PORT=4999
      - PHOENIX_COLLECTOR_ENDPOINT=http://localhost:4999

export OPENAI_API_KEY="my key"; uv run instrument.py

# instrument.py
# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "arize-phoenix",
#     "arize-phoenix-otel",
#     "llama-index",
#     "openinference-instrumentation-llama-index",
#     "opentelemetry-exporter-otlp",
#     "opentelemetry-proto>=1.12.0",
#     "opentelemetry-sdk",
# ]
# ///
from openinference.instrumentation.llama_index import LlamaIndexInstrumentor
from phoenix.otel import register
import os

# these match the env in the docker-compose.yml
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "http://localhost:4999"
os.environ["PHOENIX_GRPC_PORT"] = "4999"

# without specifying the endpoint, it defaults to localhost:4317 despite documentation saying otherwise
tracer_provider = register(endpoint=os.environ["PHOENIX_COLLECTOR_ENDPOINT"])

LlamaIndexInstrumentor().instrument(tracer_provider=tracer_provider)

You can see the tracer provider emit the configured grpc endpoint, but with the transport configured as HTTP.

@RogerHYang
Copy link
Contributor

As a workaround for the time being, you can fall back to raw otel by defining tracer_provider as follows.

import os

from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

port = os.environ["PHOENIX_GRPC_PORT"]
endpoint = f"http://localhost:{port}"
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))

@mikeldking
Copy link
Contributor

mikeldking commented Jan 10, 2025

@HKozubek agree this is confusing and we should be respecting the GRPC config. We actually designed it so that you can bail out of the defaults and specify a gRPC exporter. https://github.com/Arize-ai/phoenix/blob/main/packages/phoenix-otel/README.md

Something like

from phoenix.otel import TracerProvider, BatchSpanProcessor, GRPCSpanExporter

tracer_provider = TracerProvider()
batch_processor = BatchSpanProcessor(
    span_exporter=GRPCSpanExporter(endpoint="http://custom-endpoint.com:6789")
)
tracer_provider.add_span_processor(batch_processor)

@mikeldking mikeldking added priority: medium and removed triage issues that need triage labels Jan 10, 2025
@anticorrelator anticorrelator moved this from 📘 Todo to 👨‍💻 In progress in phoenix Jan 13, 2025
@anticorrelator
Copy link
Contributor

hi @HKozubek thanks for pointing this out! We plan on allowing the endpoint to pick up on the PHOENIX_GRPC_PORT env var soon can you can track it's progress in this PR: #6017

@anticorrelator anticorrelator moved this from 👨‍💻 In progress to 🔍. Needs Review in phoenix Jan 13, 2025
@github-project-automation github-project-automation bot moved this from 🔍. Needs Review to ✅ Done in phoenix Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: medium
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants