mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
APM: Check endpoint port and team.
This commit is contained in:
parent
6f7b242ce2
commit
d4898bec3c
6 changed files with 63 additions and 5 deletions
|
@ -635,10 +635,16 @@ tencentcloud_apm {
|
|||
# Overwrite by env SRS_TENCENTCLOUD_APM_ENABLED
|
||||
# default: off
|
||||
enabled on;
|
||||
# The APM token for authentication. See https://console.cloud.tencent.com/apm/monitor/access
|
||||
# The APM team or business system ID, to which spans belongs to. For example, the team is apm-FsOsPOIMl (just an
|
||||
# example, not available), please get your team from https://console.cloud.tencent.com/apm/monitor/team
|
||||
# Overwrite by env SRS_TENCENTCLOUD_APM_TEAM
|
||||
team apm-xxxxxxxxx;
|
||||
# The APM token for authentication. For example, the token is xzddEaegsxGadEpGEDFx (just an example, not available),
|
||||
# please get your token from https://console.cloud.tencent.com/apm/monitor/access
|
||||
# Overwrite by env SRS_TENCENTCLOUD_APM_TOKEN
|
||||
token xxxxxxxx;
|
||||
# The APM endpoint. See https://github.com/open-telemetry/opentelemetry-go/tree/main/exporters/otlp/otlptrace
|
||||
# Please note that 4317 is for GRPC/HTTP2, while SRS only support HTTP and the port shoule be 55681.
|
||||
# Overwrite by env SRS_TENCENTCLOUD_APM_ENDPOINT
|
||||
endpoint ap-guangzhou.apm.tencentcs.com:55681;
|
||||
# The service.name of resource.
|
||||
|
|
|
@ -3468,6 +3468,25 @@ bool SrsConfig::get_tencentcloud_apm_enabled()
|
|||
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
||||
}
|
||||
|
||||
string SrsConfig::get_tencentcloud_apm_team()
|
||||
{
|
||||
SRS_OVERWRITE_BY_ENV_STRING("SRS_TENCENTCLOUD_APM_TEAM");
|
||||
|
||||
static string DEFAULT = "";
|
||||
|
||||
SrsConfDirective* conf = root->get("tencentcloud_apm");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("team");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return conf->arg0();
|
||||
}
|
||||
|
||||
string SrsConfig::get_tencentcloud_apm_token()
|
||||
{
|
||||
SRS_OVERWRITE_BY_ENV_STRING("SRS_TENCENTCLOUD_APM_TOKEN");
|
||||
|
|
|
@ -470,6 +470,7 @@ public:
|
|||
virtual std::string get_tencentcloud_cls_endpoint();
|
||||
virtual std::string get_tencentcloud_cls_topic_id();
|
||||
virtual bool get_tencentcloud_apm_enabled();
|
||||
virtual std::string get_tencentcloud_apm_team();
|
||||
virtual std::string get_tencentcloud_apm_token();
|
||||
virtual std::string get_tencentcloud_apm_endpoint();
|
||||
virtual std::string get_tencentcloud_apm_service_name();
|
||||
|
|
|
@ -1962,7 +1962,7 @@ ISrsApmSpan* SrsApmSpan::set_kind(SrsApmKind kind)
|
|||
|
||||
ISrsApmSpan* SrsApmSpan::as_child(ISrsApmSpan* parent)
|
||||
{
|
||||
// Should be child of different parents.
|
||||
// Should not be child of multiple parent spans.
|
||||
if (child_) return this;
|
||||
|
||||
// For child, always load parent from context.
|
||||
|
@ -2107,16 +2107,40 @@ srs_error_t SrsApmClient::initialize()
|
|||
return err;
|
||||
}
|
||||
|
||||
team_ = _srs_config->get_tencentcloud_apm_team();
|
||||
token_ = _srs_config->get_tencentcloud_apm_token();
|
||||
endpoint_ = _srs_config->get_tencentcloud_apm_endpoint();
|
||||
service_name_ = _srs_config->get_tencentcloud_apm_service_name();
|
||||
debug_logging_ = _srs_config->get_tencentcloud_apm_debug_logging();
|
||||
srs_trace("Initialize TencentCloud APM, token=%dB, endpoint=%s, service_name=%s, debug_logging=%d", token_.length(), endpoint_.c_str(), service_name_.c_str(), debug_logging_);
|
||||
srs_trace("Initialize TencentCloud APM, team=%s, token=%dB, endpoint=%s, service_name=%s, debug_logging=%d", team_.c_str(), token_.length(), endpoint_.c_str(), service_name_.c_str(), debug_logging_);
|
||||
|
||||
// Check authentication, the team or token.
|
||||
if (team_.empty()) {
|
||||
return srs_error_new(ERROR_APM_AUTH, "No authentication team for APM");
|
||||
}
|
||||
if (token_.empty()) {
|
||||
return srs_error_new(ERROR_APM_AUTH, "No authentication token for APM");
|
||||
}
|
||||
|
||||
// Please note that 4317 is for GRPC/HTTP2, while SRS only support HTTP and the port shoule be 55681.
|
||||
if (srs_string_contains(endpoint_, ":4317")) {
|
||||
return srs_error_new(ERROR_APM_ENDPOINT, "Port 4317 is for GRPC over HTTP2 for APM");
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsApmClient::report()
|
||||
{
|
||||
srs_error_t err = do_report();
|
||||
if (err != srs_success) {
|
||||
return srs_error_wrap(err, "team=%s, token=%dB", team_.c_str(), token_.length());
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsApmClient::do_report()
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
@ -2133,6 +2157,8 @@ srs_error_t SrsApmClient::report()
|
|||
rs->resource()->add_addr(SrsOtelAttribute::kv("service.name", service_name_));
|
||||
// For Tencent Cloud APM authentication, see https://console.cloud.tencent.com/apm/monitor/access
|
||||
rs->resource()->add_addr(SrsOtelAttribute::kv("token", token_));
|
||||
// For Tencent Cloud APM debugging, see https://console.cloud.tencent.com/apm/monitor/team
|
||||
rs->resource()->add_addr(SrsOtelAttribute::kv("tapm.team", team_));
|
||||
|
||||
SrsOtelScopeSpans* spans = rs->append();
|
||||
spans->scope()->name_ = "srs";
|
||||
|
@ -2198,7 +2224,7 @@ srs_error_t SrsApmClient::report()
|
|||
|
||||
if (debug_logging_) {
|
||||
string server_id = SrsStatistic::instance()->server_id();
|
||||
srs_trace("APM write logs=%d, size=%dB, server_id=%s", spans->size(), body.length(), server_id.c_str());
|
||||
srs_trace("APM write team=%s, token=%dB, logs=%d, size=%dB, server_id=%s", team_.c_str(), token_.length(), spans->size(), body.length(), server_id.c_str());
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
|
@ -493,6 +493,7 @@ class SrsApmClient
|
|||
private:
|
||||
bool enabled_;
|
||||
uint64_t nn_spans_;
|
||||
std::string team_;
|
||||
std::string token_;
|
||||
std::string endpoint_;
|
||||
std::string service_name_;
|
||||
|
@ -504,6 +505,9 @@ public:
|
|||
public:
|
||||
srs_error_t initialize();
|
||||
srs_error_t report();
|
||||
private:
|
||||
srs_error_t do_report();
|
||||
public:
|
||||
bool enabled();
|
||||
uint64_t nn_spans();
|
||||
public:
|
||||
|
|
|
@ -97,7 +97,9 @@
|
|||
XX(ERROR_PB_NO_SPACE , 1084, "ProtobufNoSpace", "Failed to encode protobuf for no buffer space left") \
|
||||
XX(ERROR_CLS_INVALID_CONFIG , 1085, "ClsConfig", "Invalid configuration for TencentCloud CLS") \
|
||||
XX(ERROR_CLS_EXCEED_SIZE , 1086, "ClsExceedSize", "CLS logs exceed max size 5MB") \
|
||||
XX(ERROR_APM_EXCEED_SIZE , 1087, "ApmExceedSize", "APM logs exceed max size 5MB")
|
||||
XX(ERROR_APM_EXCEED_SIZE , 1087, "ApmExceedSize", "APM logs exceed max size 5MB") \
|
||||
XX(ERROR_APM_ENDPOINT , 1088, "ApmEndpoint", "APM endpoint is invalid") \
|
||||
XX(ERROR_APM_AUTH , 1089, "ApmAuth", "APM team or token is invalid") \
|
||||
|
||||
/**************************************************/
|
||||
/* RTMP protocol error. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue