File size: 1,078 Bytes
49b2277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import time
from dotenv import load_dotenv
import logging

# Load envs
load_dotenv(override=True)

# Enable debug logs
import sys
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logging.getLogger("langfuse").setLevel(logging.DEBUG)


import langfuse
from langfuse import observe

# 1. Print config to verify keys
print(f"Host: {os.environ.get('LANGFUSE_HOST')}")
print(f"Public Key: {os.environ.get('LANGFUSE_PUBLIC_KEY')}")

# 2. Define observed function
@observe(name="test-trace-script")
def run_test():
    print("Executing observed function...")
    time.sleep(0.1)
    return "Test successful"

# 3. Run
run_test()

# 4. Flush / Wait
print("Waiting for background upload...")
time.sleep(3)

try:
    from langfuse import Langfuse
    # Try to flush using a new client instance (hoping for shared state or just to test connection)
    client = Langfuse()
    client.flush()
    print("Flush called on client instance.")
except Exception as e:
    print(f"Flush failed: {e}")

print("Script finished.")