pydantic / logfire

Uncomplicated Observability for Python and beyond! 🪵🔥
https://docs.pydantic.dev/logfire/
MIT License
1.93k stars 59 forks source link

Stripe Integration? #118

Open samuelcolvin opened 4 months ago

samuelcolvin commented 4 months ago

Description

Stripe's SDK has 4M downloads a month, that's significantly more than the other libraries we've been considering integrations with.

Also requests to Stripe are arguably even more precious that LLM queries, so observability seems particularly useful.

ozleryildirim2 commented 4 months ago

help please stripe

I cannot receive the payment made to my Stripe account, I have made changes many times, the error has gotten bigger and now, even though I have entered my information correctly, I am giving an address verification error and I cannot activate my account, so I cannot receive the payment of the money in the account, they banned me, I think it has been 1 year.

My other problem is, I want to access the control panel from the e-mail sent on a past date, but there is no e-mail, I cannot find it, so I cannot activate my account.

While creating a new membership, before switching from the test mode to the live mode, it says that the restriction is not acceptable to confirm. Could it be because my API address is blocked? I cannot create a healthy membership. Turkey does not provide any kind of service. Am I signing up with the information of that country with a VPN? Even if it does not work, if I send 1 dollar to try it, it will be restricted.

When I connect it to my website, I cannot work because there will be restrictions when payments are made. I integrate it in 2D and there are restrictions when there are incoming payments. Is there anyone who can help me with this? I do not want to connect the APIs to the website and try to persuade these stripe approvals.

Kludex commented 1 month ago

@samuelcolvin Can you give more details about what's interesting here?

All the stripe objects on the client seem to inherit the following: https://github.com/stripe/stripe-python/blob/5e5eb48993c8c964abb7a93d37a817bfdf674d9e/stripe/_stripe_object.py#L80

Maybe we can do something about it? What do you think?

Kludex commented 1 month ago

Stripe has a logger that we can use for this.

Kludex commented 1 month ago

I did some investigation here.

As I said, stripe uses a logger:

logger: logging.Logger = logging.getLogger("stripe")

With this snippet, you can already see it in use:

import logging
import os

import dotenv
import stripe
from rich.logging import RichHandler

import logfire

logfire.configure(console=False)

FORMAT = '%(message)s'
logging.basicConfig(
    level='DEBUG',
    format=FORMAT,
    datefmt='[%X]',
    handlers=[RichHandler(), logfire.LogfireLoggingHandler()],
)

dotenv.load_dotenv()

client = stripe.StripeClient(api_key=os.environ['STRIPE_SECRET_KEY'])

with logfire.span('list_products'):
    products = client.products.list()

The console output:

❯ python main.py
Logfire project URL: https://logfire.pydantic.dev/kludex/my-project
[12:00:57] DEBUG    load_ssl_context                                                                                                                   _config.py:80
                    verify='/Users/marcelotryle/dev/pydantic/logfire/.venv/lib/python3.12/site-packages/stripe/data/ca-certificates.crt' cert=None                  
                    trust_env=True http2=False                                                                                                                      
           DEBUG    load_verify_locations                                                                                                             _config.py:146
                    cafile='/Users/marcelotryle/dev/pydantic/logfire/.venv/lib/python3.12/site-packages/stripe/data/ca-certificates.crt'                            
           INFO     message='Request to Stripe api' method=get url=https://api.stripe.com/v1/products                                                   _util.py:128
           DEBUG    api_version=2024-06-20 message='Post details' post_data=                                                                            _util.py:121
           DEBUG    Starting new HTTPS connection (1): api.stripe.com:443                                                                     connectionpool.py:1051
           DEBUG    https://api.stripe.com:443 "GET /v1/products HTTP/11" 200 678                                                              connectionpool.py:546
           INFO     message='Stripe API response' path=https://api.stripe.com/v1/products response_code=200                                             _util.py:128
           DEBUG    body='{\n  "object": "list",\n  "data": [\n    {\n      "id": "prod_QRRsAs4oOhniSu",\n      "object": "product",\n      "active":   _util.py:121
                    true,\n      "attributes": [],\n      "created": 1720512044,\n      "default_price": "price_1PiaDGB7axlxkstuaOyy5kn8",\n                        
                    "description": null,\n      "images": [],\n      "livemode": false,\n      "marketing_features": [],\n      "metadata": {},\n                   
                    "name": "Logfire Service",\n      "package_dimensions": null,\n      "shippable": null,\n      "statement_descriptor": null,\n                  
                    "tax_code": "txcd_20030000",\n      "type": "service",\n      "unit_label": null,\n      "updated": 1722591869,\n      "url":                   
                    null\n    }\n  ],\n  "has_more": false,\n  "url": "/v1/products"\n}' message='API response body'                                                
           DEBUG    link=https://dashboard.stripe.com/test/logs/req_u5SowCdY2lntte message='Dashboard link for request'                                 _util.py:121
           DEBUG    Starting new HTTPS connection (1): logfire-api.pydantic.dev:443                                                           connectionpool.py:1051
Starting new HTTPS connection (1): logfire-api.pydantic.dev:443
           DEBUG    Starting new HTTPS connection (2): logfire-api.pydantic.dev:443                                                           connectionpool.py:1051
Starting new HTTPS connection (2): logfire-api.pydantic.dev:443
[12:00:58] DEBUG    https://logfire-api.pydantic.dev:443 "POST /v1/metrics HTTP/11" 200 2                                                      connectionpool.py:546
https://logfire-api.pydantic.dev:443 "POST /v1/metrics HTTP/11" 200 2
           DEBUG    https://logfire-api.pydantic.dev:443 "POST /v1/traces HTTP/11" 200 2                                                       connectionpool.py:546
https://logfire-api.pydantic.dev:443 "POST /v1/traces HTTP/11" 200 2

As we can see, the body information is available on the DEBUG level. We may be able to use that on our UI.

Kludex commented 1 month ago

I talked to Samuel, and the idea would be to monkeypatch the HTTPClient, and create a span with otel scope "stripe".

ozleryildirim2 commented 1 month ago

I don't know how I can fix this, I can't fix it in the way you mentioned, I would like you to send me your e-mail address here and make the necessary arrangements for me.

Marcelo Trylesinski @.***>, 6 Ağu 2024 Sal, 15:07 tarihinde şunu yazdı:

I talked to Samuel, and the idea would be to monkeypatch the HTTPClient, and create a span with otel scope "stripe".

— Reply to this email directly, view it on GitHub https://github.com/pydantic/logfire/issues/118#issuecomment-2271132744, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFFVWKDQVKLQ7PTNEUYOX4DZQC4AFAVCNFSM6AAAAABHG4JGN6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZRGEZTENZUGQ . You are receiving this because you commented.Message ID: @.***>

ozleryildirim2 commented 1 month ago

Thanks for be interested

Marcelo Trylesinski @.***>, 6 Ağu 2024 Sal, 12:23 tarihinde şunu yazdı:

Stripe has a logger that we can use for this.

— Reply to this email directly, view it on GitHub https://github.com/pydantic/logfire/issues/118#issuecomment-2270808418, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFFVWKB5IXYQQETCB5QEX73ZQCIYVAVCNFSM6AAAAABHG4JGN6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZQHAYDQNBRHA . You are receiving this because you commented.Message ID: @.***>

Kludex commented 1 day ago

I've created docs on how to integrate with Stripe: https://github.com/pydantic/logfire/pull/425

Kludex commented 11 hours ago

We've documented it. I think it's enough for now... Do you disagree @samuelcolvin ?