Record a PubSub message (published or received). Args: direction: Message direction ('publish' or 'receive') channel: Pub/Sub channel name sharded: True if sharded Pub/Sub channel Example: >>> record_pubsub_message(PubSubDirection.PUBLISH, 'channel', Fa
(
direction: PubSubDirection,
channel: Optional[str] = None,
sharded: Optional[bool] = None,
)
| 451 | |
| 452 | |
| 453 | def record_pubsub_message( |
| 454 | direction: PubSubDirection, |
| 455 | channel: Optional[str] = None, |
| 456 | sharded: Optional[bool] = None, |
| 457 | ) -> None: |
| 458 | """ |
| 459 | Record a PubSub message (published or received). |
| 460 | |
| 461 | Args: |
| 462 | direction: Message direction ('publish' or 'receive') |
| 463 | channel: Pub/Sub channel name |
| 464 | sharded: True if sharded Pub/Sub channel |
| 465 | |
| 466 | Example: |
| 467 | >>> record_pubsub_message(PubSubDirection.PUBLISH, 'channel', False) |
| 468 | """ |
| 469 | global _metrics_collector |
| 470 | |
| 471 | if _metrics_collector is None: |
| 472 | _metrics_collector = _get_or_create_collector() |
| 473 | if _metrics_collector is None: |
| 474 | return |
| 475 | |
| 476 | # Check if channel names should be hidden |
| 477 | effective_channel = channel |
| 478 | if channel is not None: |
| 479 | config = _get_config() |
| 480 | if config is not None and config.hide_pubsub_channel_names: |
| 481 | effective_channel = None |
| 482 | |
| 483 | try: |
| 484 | _metrics_collector.record_pubsub_message( |
| 485 | direction=direction, |
| 486 | channel=effective_channel, |
| 487 | sharded=sharded, |
| 488 | ) |
| 489 | except Exception: |
| 490 | pass |
| 491 | |
| 492 | |
| 493 | @deprecated_args( |