Commit bba04fc
committed
Add OpenTelemetry instrumentation for Model Context Protocol (MCP)
This commit introduces a new instrumentation package for the Model Context
Protocol (MCP), enabling automatic distributed tracing for MCP client-server
interactions.
Key Features:
- Automatic instrumentation of MCP client sessions and server handlers
- Support for both stdio and HTTP/SSE transports
- W3C trace context propagation across MCP messages
- Comprehensive span attributes following semantic conventions
- Tool calls, resource reads, prompt handling, and session lifecycle tracing
Package Structure:
- Core instrumentation: McpInstrumentor with automatic wrapping
- Semantic attributes: MCP-specific span attributes and conventions
- Test coverage: Unit tests for instrumentor, server, and session wrappers
- Examples: stdio (simple-client-server) and HTTP/SSE transport demos
- Documentation: README, CHANGELOG, and example-specific guides
Technical Implementation:
- Wraps mcp.ClientSession and mcp.server.Server classes
- Injects trace context into message metadata
- Extracts and propagates context across transport boundaries
- Records exceptions and sets span status appropriately
- Requires Python >=3.10 (MCP SDK requirement)
CI/CD Updates:
- Added MCP instrumentation to test workflows
- Updated lint configuration for new package
- Disabled pypy3 tests (Python 3.10+ requirement)
- Integrated into eachdist.ini and bootstrap generation
Examples:
- simple-client-server: stdio transport with tool calls and resources
- http-transport: HTTP/SSE transport with distributed tracing
- Both include Jaeger trace visualizations and setup instructions"1 parent ba0644f commit bba04fc
File tree
46 files changed
+6822
-1014
lines changed- .github/workflows
- instrumentation-genai
- opentelemetry-instrumentation-mcp
- examples
- http-transport
- client
- server
- simple-client-server
- client
- server
- mcp_simple_tool
- src/opentelemetry/instrumentation/mcp
- tests
- scripts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
46 files changed
+6822
-1014
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
92 | 111 | | |
93 | 112 | | |
94 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
643 | 795 | | |
644 | 796 | | |
645 | 797 | | |
| |||
4629 | 4781 | | |
4630 | 4782 | | |
4631 | 4783 | | |
4632 | | - | |
4633 | | - | |
4634 | | - | |
4635 | | - | |
4636 | | - | |
4637 | | - | |
4638 | | - | |
4639 | | - | |
4640 | | - | |
4641 | | - | |
4642 | | - | |
4643 | | - | |
4644 | | - | |
4645 | | - | |
4646 | | - | |
4647 | | - | |
4648 | | - | |
4649 | | - | |
4650 | | - | |
4651 | | - | |
4652 | | - | |
4653 | | - | |
4654 | | - | |
4655 | | - | |
4656 | | - | |
4657 | | - | |
4658 | | - | |
4659 | | - | |
4660 | | - | |
4661 | | - | |
4662 | | - | |
4663 | | - | |
4664 | | - | |
4665 | | - | |
4666 | | - | |
4667 | | - | |
4668 | | - | |
4669 | | - | |
4670 | | - | |
4671 | | - | |
4672 | | - | |
4673 | | - | |
4674 | | - | |
4675 | | - | |
4676 | | - | |
4677 | | - | |
4678 | | - | |
4679 | | - | |
4680 | | - | |
4681 | | - | |
4682 | | - | |
4683 | | - | |
4684 | | - | |
4685 | | - | |
4686 | | - | |
4687 | | - | |
4688 | | - | |
4689 | | - | |
4690 | | - | |
4691 | | - | |
4692 | | - | |
4693 | | - | |
4694 | | - | |
4695 | | - | |
4696 | | - | |
4697 | | - | |
4698 | | - | |
4699 | | - | |
4700 | | - | |
4701 | | - | |
4702 | | - | |
4703 | | - | |
4704 | | - | |
4705 | | - | |
4706 | | - | |
4707 | | - | |
4708 | | - | |
4709 | | - | |
4710 | | - | |
4711 | | - | |
4712 | | - | |
4713 | | - | |
4714 | | - | |
4715 | | - | |
4716 | | - | |
4717 | | - | |
4718 | | - | |
4719 | | - | |
4720 | | - | |
4721 | | - | |
4722 | | - | |
4723 | | - | |
4724 | | - | |
4725 | | - | |
4726 | | - | |
4727 | | - | |
4728 | | - | |
4729 | | - | |
4730 | | - | |
4731 | | - | |
4732 | | - | |
4733 | | - | |
4734 | | - | |
4735 | | - | |
4736 | | - | |
4737 | | - | |
4738 | | - | |
4739 | | - | |
4740 | | - | |
4741 | | - | |
4742 | | - | |
4743 | | - | |
4744 | | - | |
4745 | | - | |
4746 | | - | |
4747 | | - | |
4748 | | - | |
4749 | | - | |
4750 | | - | |
4751 | | - | |
4752 | | - | |
4753 | | - | |
4754 | | - | |
4755 | | - | |
4756 | | - | |
4757 | | - | |
4758 | | - | |
4759 | | - | |
4760 | | - | |
4761 | | - | |
4762 | | - | |
4763 | | - | |
4764 | | - | |
4765 | | - | |
4766 | | - | |
4767 | | - | |
4768 | | - | |
4769 | | - | |
4770 | | - | |
4771 | | - | |
4772 | | - | |
4773 | | - | |
4774 | | - | |
4775 | | - | |
4776 | | - | |
4777 | | - | |
4778 | | - | |
4779 | | - | |
4780 | | - | |
4781 | | - | |
4782 | | - | |
4783 | | - | |
0 commit comments