diff --git a/zipkin-web/app/assets/javascripts/application-show.js b/zipkin-web/app/assets/javascripts/application-show.js index 3bc6bbb69b2..17b9aa7d93b 100644 --- a/zipkin-web/app/assets/javascripts/application-show.js +++ b/zipkin-web/app/assets/javascripts/application-show.js @@ -22,6 +22,77 @@ Zipkin.Application.Show = (function() { , TEMPLATES = Zipkin.Util.TEMPLATES ; + var exportTrace = function(traceId, clockSkew) { + window.open(root_url + "traces/get_trace.json?id=" + traceId + "&adjust_clock_skew=" + clockSkew); + }; + + var getTraceSuccess = function(data){ + data.has_filtered_spans = data.spans.length > Zipkin.Config.MIN_SPANS_TO_FILTER; + + templatize(TEMPLATES.GET_TRACE, function(template) { + + Zipkin.Base.enableClockSkewBtn(); + + /* Construct Zipkin.Span, Zipkin.Annotation, and Zipkin.KvAnnotation objects to pass on */ + var spanMap = {} + , spans = [] + , annotations = [] + , kvAnnotations = [] + , kvAnnotationsMap = {} + ; + + $.each(data.spans, function(i, span) { + var s = Zipkin.fromRawSpan(span); + spanMap[s.id] = s; + spans.push(s); + }); + + $.each(data.kv_annotations, function(spanId, kvAs) { + var span = spanMap[spanId]; + $.each(kvAs, function(i, kvA) { + var annotation = Zipkin.fromRawKvAnnotation(kvA); + span.addKvAnnotation(annotation); + annotation.setSpan(span); + + kvAnnotations.push(annotation); + }); + kvAnnotationsMap[spanId] = kvAs + }); + + $.each(data.annotations, function(i, val) { + var spanId = val.id; + var span = spanMap[spanId]; + var a = Zipkin.fromRawAnnotation(val); + + span.addAnnotation(a); + a.setSpan(span); + annotations.push(a); + + // Attach the kv annotations for trace timeline + if (kvAnnotationsMap.hasOwnProperty(spanId)) { + var kvAs = kvAnnotationsMap[spanId]; + val.binary_annotations = kvAs; + val.has_binary_annotations = true; + } else { + val.has_binary_annotations = false; + } + }); + + var content = template.render(data); + + $('#loading-data').hide(); + $('#trace-content').html(content); + $('#trace-content').show(); + + /* Bind the export trace data to the handler */ + $(".export-trace-btn").click(function(e) { + exportTrace(traceId, Zipkin.Base.clockSkewState() ? 'true' : 'false'); + }); + + Zipkin.GetTrace.initialize(data.trace, spans, annotations, kvAnnotations); + }) + }; + var initialize = function (traceId) { Zipkin.Base.initialize(); @@ -43,67 +114,7 @@ Zipkin.Application.Show = (function() { type: 'GET', url: root_url + url_method, data: query_data, - success: function(data){ - data.has_filtered_spans = data.spans.length > Zipkin.Config.MIN_SPANS_TO_FILTER; - - templatize(TEMPLATES.GET_TRACE, function(template) { - - Zipkin.Base.enableClockSkewBtn(); - - /* Construct Zipkin.Span, Zipkin.Annotation, and Zipkin.KvAnnotation objects to pass on */ - var spanMap = {} - , spans = [] - , annotations = [] - , kvAnnotations = [] - , kvAnnotationsMap = {} - ; - - $.each(data.spans, function(i, span) { - var s = Zipkin.fromRawSpan(span); - spanMap[s.id] = s; - spans.push(s); - }); - - $.each(data.kv_annotations, function(spanId, kvAs) { - var span = spanMap[spanId]; - $.each(kvAs, function(i, kvA) { - var annotation = Zipkin.fromRawKvAnnotation(kvA); - span.addKvAnnotation(annotation); - annotation.setSpan(span); - - kvAnnotations.push(annotation); - }); - kvAnnotationsMap[spanId] = kvAs - }); - - $.each(data.annotations, function(i, val) { - var spanId = val.id; - var span = spanMap[spanId]; - var a = Zipkin.fromRawAnnotation(val); - - span.addAnnotation(a); - a.setSpan(span); - annotations.push(a); - - // Attach the kv annotations for trace timeline - if (kvAnnotationsMap.hasOwnProperty(spanId)) { - var kvAs = kvAnnotationsMap[spanId]; - val.binary_annotations = kvAs; - val.has_binary_annotations = true; - } else { - val.has_binary_annotations = false; - } - }); - - var content = template.render(data); - - $('#loading-data').hide(); - $('#trace-content').html(content); - $('#trace-content').show(); - - Zipkin.GetTrace.initialize(data.trace, spans, annotations, kvAnnotations); - }); - }, + success: getTraceSuccess, error: function(xhr, status, error) { $('#trace-content').hide(); $('#loading-data').hide(); @@ -121,7 +132,8 @@ Zipkin.Application.Show = (function() { }; return { - initialize: initialize + initialize: initialize, + getTraceSuccess: getTraceSuccess }; })(); diff --git a/zipkin-web/app/assets/javascripts/application-static.js b/zipkin-web/app/assets/javascripts/application-static.js new file mode 100644 index 00000000000..0f64cd9779e --- /dev/null +++ b/zipkin-web/app/assets/javascripts/application-static.js @@ -0,0 +1,55 @@ +/* + * Copyright 2012 Twitter Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*global root_url:false */ +//= require zipkin +var Zipkin = Zipkin || {}; +Zipkin.Application = Zipkin.Application || {}; +Zipkin.Application.Static = (function() { + + var hideError = function() { + $("#input-json-error").hide() + }; + + var showError = function(msg) { + $("#input-json-error-body").text(msg); + $("#input-json-error").show() + }; + + var initialize = function() { + Zipkin.Base.initialize(); + + $(window).on("click", ".js-input-json-btn", function(e) { + hideError(); + + var data = $("#input-json").val().trim(); + if (data.length === 0) { + showError("Empty!"); + return; + } + + try { + var obj = $.parseJSON(data); + Zipkin.Application.Show.getTraceSuccess(obj); + } catch (e) { + showError("Invalid JSON"); + } + }); + }; + + return { + initialize: initialize + }; +})(); \ No newline at end of file diff --git a/zipkin-web/app/views/traces/show.html.erb b/zipkin-web/app/views/traces/show.html.erb index 86bdda60960..5d7fb963587 100644 --- a/zipkin-web/app/views/traces/show.html.erb +++ b/zipkin-web/app/views/traces/show.html.erb @@ -30,6 +30,16 @@ + + <%= content_for :javascript_inline do %> $(Zipkin.Application.Show.initialize("<%= @trace_id %>")); <% end %> diff --git a/zipkin-web/app/views/traces/static.html.erb b/zipkin-web/app/views/traces/static.html.erb new file mode 100644 index 00000000000..fa2dd46ef17 --- /dev/null +++ b/zipkin-web/app/views/traces/static.html.erb @@ -0,0 +1,19 @@ +
+ +
+ +
+
+
+ x +

+
+

Input JSON

+ + +
+
+ +<%= content_for :javascript_inline do %> + $(Zipkin.Application.Static.initialize()); +<% end %> diff --git a/zipkin-web/config/routes.rb b/zipkin-web/config/routes.rb index 782e085f773..2ded1a6e813 100644 --- a/zipkin-web/config/routes.rb +++ b/zipkin-web/config/routes.rb @@ -28,6 +28,7 @@ # resources :products match 'hex/:id' => 'traces#hex' + match 'static' => 'traces#static' resources :traces, :only => [:index, :show] do collection do diff --git a/zipkin-web/public/templates/get-trace.mustache b/zipkin-web/public/templates/get-trace.mustache index 3bdd21ad62d..24a3d6dc45a 100644 --- a/zipkin-web/public/templates/get-trace.mustache +++ b/zipkin-web/public/templates/get-trace.mustache @@ -19,6 +19,11 @@ +
+ +
{{#has_filtered_spans}}